How to compare !VAR1 and !VAR2 number

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Re: How to compare !VAR1 and !VAR2 number

by imacronewbie22 on Tue Dec 27, 2016 9:28 am

Hi chivracq, thank you for responding. This is example how often code makes a mistake

Code: Select all
1011  2320          OK no-reaction
8478  3259        OK press-button
63781 24468       OK press-button
7385  1970        OK press-button
1907  562           OK no-reaction
808   294         OK press-button
328   706           OK no-reaction
14    32            OK no-reaction
1100  206       Wrong without-reaction
213   44        Wrong without-reaction
1764  2357          OK no-reaction
43    335         Wrong press-button
4952  1411        OK press-button
620   531         OK press-button
145   347           OK no-reaction
18443 15065       OK press-button
198   258           OK no-reaction
786   507         OK press-button
1176  739       Wrong without-reaction
833   446         OK press-button
2695  1242        OK press-button
2984  963       Wrong without-reaction
2851  2           OK press-button
386   554           OK no-reaction
6637  167         OK press-button
1719  433       Wrong without-reaction
19844 913       Wrong without-reaction
8260  337         OK press-button
605   307         OK press-button
347   688           OK no-reaction
7074  602         OK press-button
506   16          OK press-button
275   245         OK press-button
40732 119         OK press-button
3016  1449        OK press-button
9731  418         OK press-button


I am not sure what you suggested
imacronewbie22
 
Posts: 17
Joined: Wed Dec 14, 2016 3:57 pm

Re: How to compare !VAR1 and !VAR2 number

by chivracq on Tue Dec 27, 2016 11:37 am

imacronewbie22 wrote:Hi chivracq, thank you for responding. This is example how often code makes a mistake

Code: Select all
1011  2320          OK no-reaction
8478  3259        OK press-button
63781 24468       OK press-button
7385  1970        OK press-button
1907  562           OK no-reaction
808   294         OK press-button
328   706           OK no-reaction
14    32            OK no-reaction
1100  206       Wrong without-reaction
213   44        Wrong without-reaction
1764  2357          OK no-reaction
43    335         Wrong press-button
4952  1411        OK press-button
620   531         OK press-button
145   347           OK no-reaction
18443 15065       OK press-button
198   258           OK no-reaction
786   507         OK press-button
1176  739       Wrong without-reaction
833   446         OK press-button
2695  1242        OK press-button
2984  963       Wrong without-reaction
2851  2           OK press-button
386   554           OK no-reaction
6637  167         OK press-button
1719  433       Wrong without-reaction
19844 913       Wrong without-reaction
8260  337         OK press-button
605   307         OK press-button
347   688           OK no-reaction
7074  602         OK press-button
506   16          OK press-button
275   245         OK press-button
40732 119         OK press-button
3016  1449        OK press-button
9731  418         OK press-button


I am not sure what you suggested

Well, dunno, you didn't post your URL so I couldn't/cannot test anything, I don't know what you get (exactly) in all the Extracts and you don't follow your Vars to debug your Script, but your Script, I would think looks OK to me, but your Results show that iMacros is comparing n1 and n2 alphabetically and not arithmetically even in that one, even if I don't understand your "OK":
Code: Select all
1907  562           OK no-reaction


But anyway try this:
Code: Select all
SET Button EVAL("var n1='{{Nb_1}}', n2='{{Nb_2}}'; if((n1*1)>(n2*1)){x=1;} else{x=0;} x;")

And otherwise, follow all your Vars with 'PROMPT' or Logging and make sure as well that your 'R1 EXTRACT=HTM' is correct and your '!VAR1' as well...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6291
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: How to compare !VAR1 and !VAR2 number

by imacronewbie22 on Tue Dec 27, 2016 12:49 pm

Thank you a milion times. Yes, this script works and counts as true mathematician :)
Code: Select all
SET Button EVAL("var n1='{{Nb_1}}', n2='{{Nb_2}}'; if((n1*1)>(n2*1)){x=1;} else{x=0;} x;")

Sorry for mistake
Code: Select all
1907  562           OK no-reaction

is my brain-no reaction (pure mistake)

Thank you again and Happy New Year.
imacronewbie22
 
Posts: 17
Joined: Wed Dec 14, 2016 3:57 pm

Re: How to compare !VAR1 and !VAR2 number

by chivracq on Tue Dec 27, 2016 2:25 pm

imacronewbie22 wrote:Thank you a milion times. Yes, this script works and counts as true mathematician :)
Code: Select all
SET Button EVAL("var n1='{{Nb_1}}', n2='{{Nb_2}}'; if((n1*1)>(n2*1)){x=1;} else{x=0;} x;")

Sorry for mistake
Code: Select all
1907  562           OK no-reaction

is my brain-no reaction (pure mistake)

Thank you again and Happy New Year.

Ah OK, good to hear...! :D
(But I had already mentioned it 2 or 3 times about Alphabetical/Arithmetical, so that was not very difficult to check...)

Yep I use regularly this "x1" "Trick" myself in 'EVAL()' Statements, it's the same like what I had mentioned about 'Number()' / 'parseInt()' / 'parseFloat()' to convert if needed a String to a Number, I call it a Trick as I've never seen anybody using it so I'm not sure it works in all Browsers, I've only checked on FF/PM (Pale Moon) but I find it easier to use than those JS Functions and it's shorter as well to try to keep 'EVAL()' Statements within one Screen to avoid when possible horizontal Scrolling) and it is even capable of handling leading/trailing Spaces and leading Zeros... (not sure about Soft/Hard Returns and TAB's...)

iMacros when doing Extracts already has some Mechanism to try to "decide" if the Content of an Extract is a String or a Number but I often find it not completely reliable, especially when using 'ADD' afterwards ("3+2" can give "5" or "32") which is sws buggy with Subtractions... ("3-0" never gives "3" but always "3-0" as a String.)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6291
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Previous

Return to Data Extraction and Web Screen Scraping

Who is online

Users browsing this forum: No registered users and 2 guests

-->