Eval Compare statement

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
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
Goldclownfish
Posts: 15
Joined: Mon Apr 29, 2019 3:50 am

Eval Compare statement

Post by Goldclownfish » Mon May 13, 2019 5:05 am

:mrgreen:
Last edited by Goldclownfish on Mon May 20, 2019 6:31 am, edited 1 time in total.
chivracq
Posts: 8618
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Eval Compare statement

Post by chivracq » Mon May 13, 2019 6:06 am

Goldclownfish wrote:
Mon May 13, 2019 5:05 am

Code: Select all

windows 10, iMacros Pro 11 ,iMacro Browser
banktotal extracted value is 40348375239922 i have double checked both var's for extra spaces about 16 times havent found one

withdrawamount extracted value is 79004350000

Code: Select all

SET havecash EVAL("var d=\"{{banktotal}}\"; var s=\"{{withdrawamount}}\" ; if (d>s){var x = \"Continue\";} else {var x=\"I1\";} x;")
TAG POS=1 TYPE=SPAN ATTR=ID:{{havecash}}
have even made an eval statement to subtract them

Code: Select all

SET cashleft EVAL("var a=({{banktotal}} - {{withdrawamount}}); a;")
get this result 40269370889922

No matter what {{havecash}} ends up as I1
tried this also with the same result

Code: Select all

SET havecash EVAL("var d='({{banksplit}})'; var s='({{withdrawamount}})'; if(d >= s){var x ='Continue';} else{var x='I1';}; x;")

The only other possiblity i can think of why this doesn't work is the extraction or extractions are not the same type.

windows 10, iMacros Pro 11 ,iMacro Browser
Easiest for me if you can put your FCI at the complete top of your OP when you open a new Thread..., I don't read (the rest) until I've found it... :wink:

Buuuuut, hum-hum..., yep, one Amount is "4..." and the other one is "7...", I guess they get compared alphabetically as Strings and not numerically as Numbers...

Try this one for your first Code:

Code: Select all

SET havecash EVAL("var bt='{{banktotal}}', wa='{{withdrawamount}}'; var z; if(bt*1>wa*1){z='Continue';} else{z='I1';}; z;")
TAG POS=1 TYPE=SPAN ATTR=ID:{{havecash}}
... Or this one for your last Code:

Code: Select all

SET havecash EVAL("var bs='{{banksplit}}', wa='{{withdrawamount}}'; var z; if(bs*1>=wa*1){z='Continue';} else{z='I1';}; z;")
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
chivracq
Posts: 8618
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Eval Compare statement

Post by chivracq » Mon May 13, 2019 6:27 am

Goldclownfish wrote: I have come to the conclusion that it was simply iMacros not treating my !EXTRACT's as numbers an added .toNumber() to the end of my code to force it to behave correctly.

Code: Select all

SET withdrawamount EVAL("var a=({{newspapers}} + {{casinos}} + {{skyscrapers}} + {{hotels}} + {{condos}} + {{ristorantes}} + {{townhomes}}).toNumber(); a;")

''''''''''''''\\\\\\\\\\\\\\\WITHDRAW FROM BANK/////////////////////
TAG XPATH="/html/body/div[5]/center/div[1]/div[2]/div[1]" EXTRACT=TXT
SET bank EVAL("'{{!EXTRACT}}'.split(': ')[1].toNumber();")
SET !EXTRACT NULL
SET bank2 EVAL("var s='{{bank}}'; var z=s.split(',').join(''); z;")
SET havecash EVAL("var X=\" {{bank2}} \"; var Y=\" {{withdrawamount}} \"; if (X < Y){var x = \"Continue\";} else {var x=\"I1\";} x;")
PROMPT {{havecash}}
TAG POS=1 TYPE=SPAN ATTR=ID:{{havecash}}
Euh, yes indeed, so I was right, and your 'toNumber()' is the same like my "*1" that I prefer as it is shorter, ah-ah...!

But hum, you apply the 'toNumber()' only to your 'bank' Var which is later reused in 'bank2' and further again, but iMacros Vars are ALWAYS Strings, same with 'EVAL()', even if iMacros "tries" to "smartly" decide if Vars are then Strings or Numbers (in 'EVAL()' and 'ADD' for example) but if fails regularly..., so you should apply that 'toNumber()' to all Vars and all 'EVAL()' Statements, especially the one where you do the Comparison..., or I'm not completely sure you won't get some "unexpected" Results again... :oops:

>>>

And hum, I notice you are using several Types of Syntaxes in 'EVAL()', sometimes from me, but sometimes from some other Examples, I guess, you can better try to stick to just one Syntax that you like... :idea:

The Syntax I use myself is:

Code: Select all

SET My_Var_Name EVAL("var s='{{!EXTRACT}}', s2v='{{Some_2nd_Var}}'; var x,y,z; x=s.split(','); y=x[0]; if(y!='ABC'){z='XYZ';} else{z=s2v;}; z;")
=> I always give meaningful Names to my Vars, easy to read...
In 'EVAL()', I always use 's' for '!EXTRACT', then 'd' or 'n' if I only need 1 or 2 easy Numbers, like '!LOOP'. (I avoid 'l' or 'I' which look too much like '1', especially in the Editor...)
+ Give some short Var Names inside the 'EVAL()' that I always declare with Single Quotes. That handles a loooooot of Escaping already...! I actually nearly never need to do any Escaping..., unless there are some Double Quotes or Special Chars in the String I want to clean and/or use for/in a 'split()'...
+ I always use 'z' for the Return Value, and 'x,y', or sometimes 'w,x,y' if I need 2 or 3 Temp Vars, or for very complex Expressions, I will use 'a,b,c,d,e,f' + 'z' for the Return.
Last edited by chivracq on Mon May 13, 2019 7:23 am, edited 1 time in total.
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Goldclownfish
Posts: 15
Joined: Mon Apr 29, 2019 3:50 am

Re: Eval Compare statement

Post by Goldclownfish » Mon May 13, 2019 6:55 am

:mrgreen:
Last edited by Goldclownfish on Mon May 20, 2019 6:32 am, edited 1 time in total.
chivracq
Posts: 8618
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Eval Compare statement

Post by chivracq » Mon May 13, 2019 7:14 am

Goldclownfish wrote:
Mon May 13, 2019 6:55 am
At this point I am pretty sure iMacros isn't treating the extracted values as numbers since once i added .toNumber() to the {{withdrawamount}} line i got a NULL value. I deleted the post that u so quickly quoted also as the code had < in the comparison instead of >. I was doing some searching an ran across one of your posts in regards to comparison of values. I have to get some sleep now will work on this at a later time. Thanks again for your insight.
Oh..., no "big deal" about the "<" or ">", the Thread is about the "Principle"...

But hum, if you are getting a NULL Value, that means that you probably have some Space(s) or soft-Tab(s) or soft-Return(s) in the Extract that first need to be cleaned out with 'trim()'.
Always check the exact Content of your Extract with some:

Code: Select all

PROMPT EXTRACT:<SP>_{{!EXTRACT}}_
=> With the 2x '_' (Underscores) as Delimiters around your Var...

And hum, getting some Sleep is maybe a good Idea, for me too, ah-ah...! :twisted:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Post Reply