[SOLVED] EVAL IF ELSE #EANF# anchor not found

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
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
User avatar
Edoctoor
Posts: 34
Joined: Sun Nov 29, 2015 7:53 pm

[SOLVED] EVAL IF ELSE #EANF# anchor not found

Post by Edoctoor » Wed Dec 23, 2015 5:02 am

At the top of all my post I put this information as a rule:
iMacros Version 11.0.246.4051
Browser FireFox 42.0
OS Windows 7 Home Premium - Service Pack 1
------------------------------------------------------------------


Any time I try to use "ELSE" the if statement doesn't work as expected.
What is the syntax of the EVAL IF ELSE statement?

Code: Select all

VERSION BUILD=8940826 RECORDER=FX
TAB T=1


SET STUMPPTED  		notchanged
'SET !EXTRACT		somethingwasfound
SET !EXTRACT		#EANF#

PROMPT {{!EXTRACT}}

' if NOT found STUMPPTED = 'not found' ELSE STUMPPTED = 'found'
SET STUMPPTED EVAL("var LinkFound=\"{{!EXTRACT}}\";	d=\"FALSE\"; if ( LinkFound == \"#EANF#\" ) d=\"not found\"; ELSE d=\"found\"; d")

PROMPT "Why Why Why {{STUMPPTED}}"
Example of another attempt... I am guessing that the input might be the issue... but again... I am so tired,,, I feel blind

Code: Select all

VERSION BUILD=8940826 RECORDER=FX
TAB T=1


' Initialize variables

' if the results are notchanged.. this means the if statement fails
SET STUMPPTED        notchanged

' Two conditions... can be found or anchor not found ... choose one
SET !EXTRACT      somethingwasfound
'SET !EXTRACT      #EANF#

PROMPT {{!EXTRACT}}

' if NOT found STUMPPTED = 'not found' ELSE STUMPPTED = 'found'
SET STUMPPTED EVAL("var LinkFound=\"{{!EXTRACT}}\";   d=\"FALSE\"; if ( LinkFound == \"#EANF#\" ) {d=\"anchor not found\";} ELSE {d=\"anchor found\";}; d")

PROMPT "Why Why Why {{STUMPPTED}}"
This works... and I can use !VAR1 as a flag... but if I try to use ELSE... I can not get anything to work

Code: Select all

' Check if the macro is working as expected... if the !EXTRACTED data is 
' \"#EANF#\" ... this means (Extraction Anchor Not Found)
' ------------------------------------------------------------------------
SET !VAR1 EVAL("var LinkFound=\"{{!EXTRACT}}\";							var d='{{!VAR1}}'; if ( LinkFound == \"#EANF#\" ) {d='Ignore';}; d")
PROMPT {{!VAR1}}
In both attempts Neither "anchor not found" nor "anchor found" was returned... what is up with that?


I get all kinds of different errors such as the following
SyntaxError: missing ; before statement, line 12 (Error code: -1001)
however, most of the time the iMacros runs without an error;;
but the if statement does nothing.
BTW Error -1001 lookup returns ( -1001 Unknown error)

I assume that your waiting for me to figure this out... and I have.. figured it out.. many many times... but it is hit and miss based on guessing...
I would like to know what is wrong so I am not wasting so much time on something that appears to be very simple.

Mr. chivracq can you tell me if this fails on your computer... I always try to make my code run as standalone so it is easy to run and test.

[SOLVED] solution here...

Thank you Mr. Chivracq for the solution... I forgot the very last " ; " and I was using "ELSE" in caps.. must be "else" and I should have declared my strings out side of the EVAL statement.. many thanks for your time and efforts Mr. Chivracq ;-)

Code: Select all

    SET Anchor_Found "Anchor found"
    SET Anchor_Not_Found "Anchor not found"
    SET STUMPPTED EVAL("var s='{{!EXTRACT}}'; var af='{{Anchor_Found}}'; var anf='{{Anchor_Not_Found}}'; var x; if(s=='#EANF#'){x=anf;} else{x=af;}; x;")
Last edited by Edoctoor on Thu Dec 24, 2015 6:52 am, edited 5 times in total.
iMacros Version 11.0.246.4051
Browser FireFox 42.0
OS Windows 7 Home Premium - Service Pack 1

Before starting a topic please read the following; thank you!
http://forum.imacros.net/viewtopic.php?f=20&t=3331#p8799
chivracq
Posts: 8614
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: EVAL IF ELSE confuses me - dumb question

Post by chivracq » Wed Dec 23, 2015 8:56 am

Edoctoor wrote:At the top of all my post I put this information as a rule:

Code: Select all

iMacros Version 11.0.246.4051
Browser FireFox 42.0
OS Windows 7 Home Premium - Service Pack 1
------------------------------------------------------------------


Any time I try to use "ELSE" the if statement doesn't work as expected.
What is the syntax of the EVAL IF ELSE statement?

Code: Select all

VERSION BUILD=8940826 RECORDER=FX
TAB T=1


SET STUMPPTED  		notchanged
'SET !EXTRACT		somethingwasfound
SET !EXTRACT		#EANF#

PROMPT {{!EXTRACT}}

' if NOT found STUMPPTED = 'not found' ELSE STUMPPTED = 'found'
SET STUMPPTED EVAL("var LinkFound=\"{{!EXTRACT}}\";	d=\"FALSE\"; if ( LinkFound == \"#EANF#\" ) d=\"not found\"; ELSE d=\"found\"; d")

PROMPT "Why Why Why {{STUMPPTED}}"
Example of another attempt... I am guessing that the input might be the issue... but again... I am so tired,,, I feel blind

Code: Select all

VERSION BUILD=8940826 RECORDER=FX
TAB T=1


' Initialize variables

' if the results are notchanged.. this means the if statement fails
SET STUMPPTED        notchanged

' Two conditions... can be found or anchor not found ... choose one
SET !EXTRACT      somethingwasfound
'SET !EXTRACT      #EANF#

PROMPT {{!EXTRACT}}

' if NOT found STUMPPTED = 'not found' ELSE STUMPPTED = 'found'
SET STUMPPTED EVAL("var LinkFound=\"{{!EXTRACT}}\";   d=\"FALSE\"; if ( LinkFound == \"#EANF#\" ) {d=\"anchor not found\";} ELSE {d=\"anchor found\";}; d")

PROMPT "Why Why Why {{STUMPPTED}}"
In both attempts Neither "anchor not found" nor "anchor found" was returned... what is up with that?


I get all kinds of different errors such as the following
SyntaxError: missing ; before statement, line 12 (Error code: -1001)
however, most of the time the iMacros runs without an error;;
but the if statement does nothing.
BTW Error -1001 lookup returns ( -1001 Unknown error)

"I am guessing this is a bug since I installed the BETA and then reinstalled the normal because the BETA was not a good idea for a noob."

I have been trying to learn iMacros for over a week and this if else statement should be easy.. but I can not guess why sometimes when I write it; it works... and other times I have to spend an hour mixing it around until it works. I see lots of examples, but I can not find where the syntax is explained so I can figure out what I am missing.

Is there a 300 page manual somewhere... you can tell me... I am not afraid.. LOL

I assume that your waiting for me to figure this out... and I have.. figured it out.. many many times... but it is hit and miss based on guessing...
I would like to know what is wrong so I am not wasting so much time on something that appears to be very simple.

Mr. chivracq can you tell me if this fails on your computer... I always try to make my code run as standalone so it is easy to run and test.
Yep, no need to run your Macro, you need to use Curly Brakets {} for the Actions for 'IF' and 'ELSE'. I already gave you the/some valid Syntax that I use in this Post: (Item 4 that I mentioned...)
...
4- The Syntax I use for 'IF ELSE' Statements is: "if(s!='#EANF#'){x='FOUND';} else {x='NOT FOUND';};" (without the Outer Double Quotes.)

...

Code: Select all

SET !VAR2 EVAL("var s='{{!EXTRACT}}'; var x;  if(s!='#EANF#'){x='MATCH FOUND';} else {x='MATCH NOT FOUND';}; x;")
EDIT: But hum, your 2nd Attempt looks fine to me:

Code: Select all

SET STUMPPTED EVAL("var LinkFound=\"{{!EXTRACT}}\";   d=\"FALSE\"; if ( LinkFound == \"#EANF#\" ) {d=\"anchor not found\";} ELSE {d=\"anchor found\";}; d")
Hum, except that the 'ELSE' must be in Lowercase, I'm pretty sure about that...
What else could play a role are the Spaces in"anchor not found" that might need to be replaced by '<SP>'... To avoid eventual Problems with Spaces, I often declare Strings and Output Msg's outside the 'EVAL()':

Code: Select all

SET Anchor_Found "Anchor found"
SET Anchor_Not_Found "Anchor not found"
SET STUMPPTED EVAL("var s='{{!EXTRACT}}'; var af='{{Anchor_Found}}'; var anf='{{Anchor_Not_Found}}'; var x; if(s=='#EANF#'){x=anf;} else{x=af;}; x;")
This one should work, I would think...

And hum, you had as well a missing ';' at the end of the 'EVAL()'. The one before can be omitted I think, but not the final one...
Last edited by chivracq on Wed Dec 23, 2015 9:38 am, edited 3 times 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...
User avatar
Edoctoor
Posts: 34
Joined: Sun Nov 29, 2015 7:53 pm

Re: EVAL IF ELSE confuses me - dumb question

Post by Edoctoor » Wed Dec 23, 2015 9:18 am

Yes you did,,, and yes this works... but I didn't know why yours works and mine didn't...
I am over 55 years old... and I am not a programmer... but I would have been if I would have discovered this when I was young... I love the challenge..
Trust me your not wasting your time... I am trying my best to pay attention... it is just the tiny details... that gets me so frustrated that I would be pulling out
my hair ... that is if I had hair to pull out... he hee... Thanks oh so much again... because when I get stuck... I can not move on until I find a solution..
which makes me so tired I can not spell my name.. yet.. I refuse to give up. Again... thanks.. sorry if I am a bit of a pain... if you want I can delete this thread
so that it doesn't mess up your forum.. now that I have an answer.

May I ask...?

Code: Select all

(s!='#EANF#')
What is the " ! " for in the statement above? Let me guess .. the ! means NOT

so ( s == '#EANF#' ) means Equals
and
( s != '#EANF#' ) means NOT Equals.. I knew that one.. just pointing it out to the readers...
Last edited by Edoctoor on Wed Dec 23, 2015 1:53 pm, edited 4 times in total.
iMacros Version 11.0.246.4051
Browser FireFox 42.0
OS Windows 7 Home Premium - Service Pack 1

Before starting a topic please read the following; thank you!
http://forum.imacros.net/viewtopic.php?f=20&t=3331#p8799
chivracq
Posts: 8614
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: EVAL IF ELSE confuses me - dumb question

Post by chivracq » Wed Dec 23, 2015 9:32 am

Hum, I was still editing my previous Post while you had already posted back, you may want to review my Post... :idea:

About Age, I'm just a little bit younger and I'm not Programmer either (well, I was actually many years ago...), I'm just an Artist and DJ, so if I can master iMacros, everybody can... (And I got all my Knowledge from playing stupid Games...)
- (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...
User avatar
Edoctoor
Posts: 34
Joined: Sun Nov 29, 2015 7:53 pm

Re: [SOLVED] EVAL IF ELSE #EANF# anchor not found

Post by Edoctoor » Thu Dec 24, 2015 6:57 am

I have included your solution in the first post... and marked this thread as [SOLVED] to make it easy for people wanting the solution without scanning the whole thread.
Again, many thanks for your help, your time, and your knownledge. My next question is about batch files... but I see you already posted that solution in stackedoverflow... LOL
chivracq wrote: Ah-ah, you make it very easy for lazy Users who can't even read one full Thread..., and I'm trying to make them search the Forum..., Oooopsss...!! :shock:
I can understand your point... if you don't do this on the forum ... the forum will quickly be full of questions that could have been solved with one hour of thought... and that would deem the forum full of useless clutter... so I do understand.

However, I have taken the statement, "Garbage in; Garbage out" and changed it to "Easy in; Easy out" as I find if I get too many confusing and missleading information before I get to the final answer that my mind has to scan all that waste of time.. and all that frustration in my memory before I can remember and recall the final solution... hense... my statement... Easy in... or "clearly learned...equals exciting about the learning" well that is my two cents...
Last edited by Edoctoor on Fri Dec 25, 2015 9:25 am, edited 2 times in total.
iMacros Version 11.0.246.4051
Browser FireFox 42.0
OS Windows 7 Home Premium - Service Pack 1

Before starting a topic please read the following; thank you!
http://forum.imacros.net/viewtopic.php?f=20&t=3331#p8799
chivracq
Posts: 8614
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: [SOLVED] EVAL IF ELSE #EANF# anchor not found

Post by chivracq » Thu Dec 24, 2015 8:47 am

Edoctoor wrote:[SOLVED] solution here...

Thank you Mr. Chivracq for the solution... I forgot the very last " ; " and I was using "ELSE" in caps.. must be "else" and I should have declared my strings out side of the EVAL statement.. many thanks for your time and efforts Mr. Chivracq ;-)

Code: Select all

    SET Anchor_Found "Anchor found"
    SET Anchor_Not_Found "Anchor not found"
    SET STUMPPTED EVAL("var s='{{!EXTRACT}}'; var af='{{Anchor_Found}}'; var anf='{{Anchor_Not_Found}}'; var x; if(s=='#EANF#'){x=anf;} else{x=af;}; x;")
- Yep, the closing ';' was the most important I think... And the Curly Brackets that were missing in you first Attempt...

'- The ELSE in Caps/Lowercase is only relevant for FF, I think I remember reading somewhere (in the Wiki, I think...) a few years ago, I never tested it myself I think, I am no JavaScript Guru at all myself, so once I have a working Example, I gladly stick to it and reuse the Syntax blindly...
The Limitation was supposed to come from the FF JS Runtime Engine and not from iMacros, but if Dev know about it that they took the pain to write a Note in the Wiki about it, it's less hassle I would think to convert ELSE/ElsE/eLsE/whatever to Lowercase 'else'...

- About declaring the Strings/Output Msg's outside the 'EVAL()' Statement, it's not a Must/Should, it's just that I've noticed that sometimes for Spaces you need to use Double Quotes, sometimes Single Quotes and sometimes '<SP>' and sometimes 2 or all 3 Syntaxes all work, and you never know why...
Declaring them outside the 'EVAL()' allows to shorten and simplify the 'EVAL()' and make it/them easier to understand for sbd else (hum "for sbd else" is a wrong assumption, "for YOURSELF" I mean actually...) reading your Code, and it allows you to place them at the beg of your Script to locate them quickly if you ever want to modify the Msg without having to search through your whole Macro. Well my .iim Macros have 5000-8000 Lines of Code and I reuse some parts, so for Search and Maintenance sake, I try to declare "things" only once at the beg of my Script(s), when possible..., iMacros is not OO (Object Oriented) at all...
Edoctoor wrote:I have included your solution in the first post... and marked this thread as [SOLVED] to make it easy for people wanting the solution without scanning the whole thread.
Again, many thanks for your help, your time, and your knownledge. My next question is about batch files... but I see you already posted that solution in stackedoverflow... LOL
Ah-ah, you make it very easy for lazy Users who can't even read one full Thread..., and I'm trying to make them search the Forum..., Oooopsss...!! :shock:

Yep, glad I could help and Thanks for the Appreciation, I regularly get some hilarious big "Fuck Off" in all Languages when I ask some Users to give more Info or mention their FCI... :shock: I should make a Compil one day, hum and some Stats, I like Stats..., that can be interesting...

About your next Question about Batch Files, I'm nearly surprised you first found a Thread on SO, I rarely answer Threads there as I find the Overall Quality for iMacros Threads very low as most People posting there only try to grab some Rep-Points and maybe not even 5% of OP's mention their FCI, and I guess I must have probably included a Link to some "better" Thread on the iMacros Forum, I've already handled several Threads on "our" Forum about Batch Files and posted several times my . BAT Files (that have improved over the years as well) so I would think the iMacros Forum is a better place to find good Examples...
(SO on the other hand is better I think for pure JavaScript Questions, there are a few JS Gurus on the Forum here but they don't come very often and I only know a tiny little bit myself to be able to write my own 'EVAL()' Statements... And I don't use .js Scripts...)
But open a new Thread on the Forum (and (you can) refer to the SO Thread) if you have any Follow-up Question...
- (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