Javascript 10+2, why is 102? I need 12

Discussions and Tech Support specific to the iMacros Firefox add-on.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
frankhack1
Posts: 83
Joined: Fri Mar 20, 2009 9:12 pm

Javascript 10+2, why is 102? I need 12

Post by frankhack1 » Mon Jan 26, 2015 5:16 pm

Hi !

I'm trying PaleMoon 24.6.2 (x86) with iMacros 8.8.2

I have the following code:

Code: Select all

var myLoop;
    myLoop =  "CODE:";
myLoop +=  "SET !DATASOURCE C:\\NumAnuncios\\Data.csv" + "\n";
myLoop +=  "SET !DATASOURCE_LINE 2" + "\n";
myLoop +=  "SET !EXTRACT {{!COL1}}" + "\n";

iimPlay(myLoop);

var loop;
loop = iimGetExtract();

This is the content of Data.csv

Code: Select all

"TITLE_01","TITLE_02","TITLE_03","TITLE_04","TITLE_05"
"10","12","10","3","10"
The alert(loop) returns 10, so this is fine.

Now I want to add +2 to the amount extracted from the Data.csv, in this example the extracted data is 10 + 2, I need to return 12, but I'm getting 102 instead.

This is how I do the calculation

Code: Select all

increment = loop + 2;
alert(increment);
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Javascript 10+2, why is 102? I need 12

Post by chivracq » Tue Jan 27, 2015 4:50 am

frankhack1 wrote:Hi !

I'm trying PaleMoon 24.6.2 (x86) with iMacros 8.8.2

I have the following code:

Code: Select all

var myLoop;
    myLoop =  "CODE:";
myLoop +=  "SET !DATASOURCE C:\\NumAnuncios\\Data.csv" + "\n";
myLoop +=  "SET !DATASOURCE_LINE 2" + "\n";
myLoop +=  "SET !EXTRACT {{!COL1}}" + "\n";

iimPlay(myLoop);

var loop;
loop = iimGetExtract();

This is the content of Data.csv

Code: Select all

"TITLE_01","TITLE_02","TITLE_03","TITLE_04","TITLE_05"
"10","12","10","3","10"
The alert(loop) returns 10, so this is fine.

Now I want to add +2 to the amount extracted from the Data.csv, in this example the extracted data is 10 + 2, I need to return 12, but I'm getting 102 instead.

This is how I do the calculation

Code: Select all

increment = loop + 2;
alert(increment);
What you get as a Result doesn't really surprise me to be honest...!, 'iimGetExtract()' expects a String, too bad if "10" is a Number for you!, 10+2=102...!, yep normal...!, just like "item" + "42" gives "item42"..., you need to convert the Return of 'iimGetExtrat()' to a Number if you know it will be one, or even more simple I would think is to do your "+2" still in the .iim Macro (the .iim 'ADD' Command is more tolerant than pure JavaScript...)

And mini-Remark, I don't understand why you run your pseudo-.iim Macro as an on the fly .iim. Macro created from a .js Script, instead of running it directly as a normal .iim Macro... I don't see anything in your .js Script that justifies your Approach...

And btw, you have the right Config, PM 24.x + iMacros for FF v8.8.2, don't try to update iMacros to v8.8.3+ (current is v8.8.8), it will not work...!!!
There is a PM v25 Version available which I haven't tried/tested yet with any/all iMacros Versions available...
so using PM, I would say, stick to the same Config like me, unless you know how to test and revert easily to previous Versions for PM and iMacros: => PM v24.6.2, iMacros for FF v8.8.2 (Win7-x64)... (This Config rocks...! (Meaning it works fine and I would say that I support it, if anything goes wrong compared to the 'standard" FF corresponding Version, FF35 at this moment, I will do my best to solve the Pb for PM..., That's my Config and the Version(s) I use..., if anything goes wrong with my Config, I will always find a Solution... (well for my Needs...!))
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
janib4all
Posts: 132
Joined: Wed Jul 21, 2010 6:44 am
Location: Karachi, Sindh, Pakistan
Contact:

Re: Javascript 10+2, why is 102? I need 12

Post by janib4all » Sat Feb 21, 2015 6:55 pm

Try this:

increment = parseInt(loop) + 2;

This will convert 'loop' variable to number and then you can add any number normally.
Hire the BoT-fReeak!
botspecialist.blogspot.com
frankhack1
Posts: 83
Joined: Fri Mar 20, 2009 9:12 pm

Re: Javascript 10+2, why is 102? I need 12

Post by frankhack1 » Sun Feb 22, 2015 1:32 pm

Great answer, that small line just made my script 3 line more effective cause I was using the ADD way.

Thanks a lot!
janib4all
Posts: 132
Joined: Wed Jul 21, 2010 6:44 am
Location: Karachi, Sindh, Pakistan
Contact:

Re: Javascript 10+2, why is 102? I need 12

Post by janib4all » Mon Feb 23, 2015 1:18 pm

Thanks,

Keep all of your issues posted through proper channel for others to see and learn from your work.
Hire the BoT-fReeak!
botspecialist.blogspot.com
frankhack1
Posts: 83
Joined: Fri Mar 20, 2009 9:12 pm

Re: Javascript 10+2, why is 102? I need 12

Post by frankhack1 » Fri Feb 27, 2015 3:56 pm

You mean to post my script?
frankhack1
Posts: 83
Joined: Fri Mar 20, 2009 9:12 pm

Re: Javascript 10+2, why is 102? I need 12

Post by frankhack1 » Sun May 10, 2015 5:14 pm

So no answer, I'll assume you ask for me to post the code with the solution, here it is:

Code: Select all

var myLoop;
    myLoop =  "CODE:";
myLoop += "SET !DATASOURCE C:\\NumberOfAds.csv" + "\n";
myLoop += "SET !DATASOURCE_LINE 2" + "\n";
myLoop += "SET !EXTRACT {{!COL1}}" + "\n";

iimPlay(myLoop);

var loop;
loop = iimGetExtract();
loop = parseInt(loop) + 2;
So I get whatever number is inside NumberOfAds.csv plus 2, for example I have the number 7 inside the NumberOfAds.csv so I get 9 as result

Thanks for your help
Post Reply