SET !LOOP from Eval

Discussions and Tech Support related to the iMacros Google Chrome extension.
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.
Post Reply
les_stockton
Posts: 32
Joined: Sun Mar 06, 2011 11:30 pm

SET !LOOP from Eval

Post by les_stockton » Fri Oct 19, 2018 11:31 pm

Windows 10
Chrome: Version 69.0.3497.100 (Official Build) (64-bit)
iMacros: 10.0.5


I'm trying to set the !LOOP variable using EVAL. getting an error

BadParameter: !LOOP must be integer,

Code: Select all

SET !VAR1 EVAL("var c1='{{!COL1}}'; var z=c1.length; z;")
SET !LOOP EVAL(parseInt("({{!VAR1}}<1)?1:{{!LOOP}}"))
Essentially, this is run from Play Loop, and the hope is to iterate through a text file line by line. It semi-works, but fails here when it finally gets a line length (from !COL1 being 0 length). When it is 0 length, I want to start the !LOOP variable over to be 1 and be able to iterate again. But I get that error.
chivracq
Posts: 7715
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: SET !LOOP from Eval

Post by chivracq » Sat Oct 20, 2018 2:26 am

les_stockton wrote:Windows 10
Chrome: Version 69.0.3497.100 (Official Build) (64-bit)
iMacros: 10.0.5

I'm trying to set the !LOOP variable using EVAL. getting an error

BadParameter: !LOOP must be integer,

Code: Select all

SET !VAR1 EVAL("var c1='{{!COL1}}'; var z=c1.length; z;")
SET !LOOP EVAL(parseInt("({{!VAR1}}<1)?1:{{!LOOP}}"))
Essentially, this is run from Play Loop, and the hope is to iterate through a text file line by line. It semi-works, but fails here when it finally gets a line length (from !COL1 being 0 length). When it is 0 length, I want to start the !LOOP variable over to be 1 and be able to iterate again. But I get that error.
Pfff..., dunno, use the "secure" Syntax I used in your previous Thread for me to debug it... (is the Syntax that apparently now works for your '!VAR1' Var :idea: ), I'm not going to convert all your 'EVAL()' Statements to a Syntax "that works" because you prefer to use some buggy/simplified Syntax...! :roll:

Hum, and toch v10.0.5 for CR, ah-ah...! => 'Free' or 'PE'...?

Bad Practice in my Opinion to use 'EVAL()' directly in 'TAG' or Built-in Vars Statements, nearly impossible to debug... :idea:
I can understand the "Urge" if you are using the 'Free' Edition for v10.0.x for CR/FF (to "save" 1 Line because of the 50 Line Limitation), but pfff, you can rather use some separate Var to first to debug your 'EVAL()' Statement before integrating it inside some other Statement once you know that your 'EVAL()' works like expected... No way to debug it otherwise if it doesn't work... :idea:
Last edited by chivracq on Sat Oct 20, 2018 2:41 am, edited 1 time in total.
- (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...
les_stockton
Posts: 32
Joined: Sun Mar 06, 2011 11:30 pm

Re: SET !LOOP from Eval

Post by les_stockton » Sat Oct 20, 2018 2:38 am

Yes. I changed that line to your syntax and it works better.
Now I'm frustrated because when I finally loop beyond the number of lines in the datasource,

Code: Select all

SET !DATASOURCE_LINE {{!LOOP}}
gets an error, which is fine, but it doesn't set !COL1 to blank, so my check for the length of !COL1 never goes to zero.
Hmmm.
I'll have to figure a strategy for this. If only I could check for a specific error on that set datasource_line command, and if I get that error, I could simply set the !LOOP back to 1 like I want.
chivracq
Posts: 7715
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: SET !LOOP from Eval

Post by chivracq » Sat Oct 20, 2018 2:51 am

les_stockton wrote:Yes. I changed that line to your syntax and it works better.
Now I'm frustrated because when I finally loop beyond the number of lines in the datasource,

Code: Select all

SET !DATASOURCE_LINE {{!LOOP}}
gets an error, which is fine, but it doesn't set !COL1 to blank, so my check for the length of !COL1 never goes to zero.
Hmmm.
I'll have to figure a strategy for this. If only I could check for a specific error on that set datasource_line command, and if I get that error, I could simply set the !LOOP back to 1 like I want.
hum, I still edited my previous Post while you were or had already posted this one... :wink:

Hum..., "gets an error" => pfff, what Error...? :roll:

iMacros by design "accepts" the first empty Row, and only stops after 2 empty Rows, but some '!COLn'.length should still return "0" if you are using 'EVAL()' for some further Conditional Logic...

But hum, any chance you could post in just one Thread the whole and complete "Logic" of your Scenario...? I will probably find some direct Solution for you instead of answering 10 half-Workarounds on half-Workarounds...! :idea:
- (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...
les_stockton
Posts: 32
Joined: Sun Mar 06, 2011 11:30 pm

Re: SET !LOOP from Eval

Post by les_stockton » Sat Oct 20, 2018 3:00 am

it clumsily works now, although I get a type error on the first pass since !VAR2 isn't set the first time.

Code: Select all

SET !ERRORIGNORE YES
SET !DATASOURCE C:\Users\stockton\InputFiles\urls03.txt
SET !DATASOURCE_COLUMNS 1
SET !DATASOURCE_LINE {{!LOOP}}
SET !VAR1 EVAL("var c1='{{!COL1}}'; var z=c1.length; z;")

SET !TIMEOUT_PAGE 45

SET myDelay EVAL("var randomNumber=Math.floor(Math.random()*10 + 1); randomNumber;")
SET myDelay EVAL("var min = 1; var max = 6; var randomNumber = Math.floor(Math.random() * (max - min + 1)) + min; randomNumber;")
'
URL GOTO={{!COL1}}
WAIT SECONDS={{myDelay}}
CLEAR www.flickr.com
SET !LOOP EVAL("var z={{!LOOP}};if('{{!VAR2}}' == '{{!URLCURRENT}}'){ z=1;}; z;")
SET !VAR2 {{!URLCURRENT}}
chivracq
Posts: 7715
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: SET !LOOP from Eval

Post by chivracq » Sat Oct 20, 2018 3:18 am

les_stockton wrote:it clumsily works now, although I get a type error on the first pass since !VAR2 isn't set the first time.

Code: Select all

SET !ERRORIGNORE YES
SET !DATASOURCE C:\Users\stockton\InputFiles\urls03.txt
SET !DATASOURCE_COLUMNS 1
SET !DATASOURCE_LINE {{!LOOP}}
SET !VAR1 EVAL("var c1='{{!COL1}}'; var z=c1.length; z;")

SET !TIMEOUT_PAGE 45

SET myDelay EVAL("var randomNumber=Math.floor(Math.random()*10 + 1); randomNumber;")
SET myDelay EVAL("var min = 1; var max = 6; var randomNumber = Math.floor(Math.random() * (max - min + 1)) + min; randomNumber;")
'
URL GOTO={{!COL1}}
WAIT SECONDS={{myDelay}}
CLEAR www.flickr.com
SET !LOOP EVAL("var z={{!LOOP}};if('{{!VAR2}}' == '{{!URLCURRENT}}'){ z=1;}; z;")
SET !VAR2 {{!URLCURRENT}}
Hum, your script is indeed completely "clumsy", hum, I would say rather "completely buggy", ah-ah...! Pfff, sorry, think a bit, you've been using iMacros since 2011, come on, wake up a bit, ah-ah...! :shock:

Is nearly an Insult to tell you what is wrong, think a bit, ah-ah...! :wink:
- (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...
les_stockton
Posts: 32
Joined: Sun Mar 06, 2011 11:30 pm

Re: SET !LOOP from Eval

Post by les_stockton » Sat Oct 20, 2018 3:22 am

I don't use imacros every day. The last time I wrote any imacros was probably a year ago. I have to relearn some of it every time I use it.
chivracq
Posts: 7715
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: SET !LOOP from Eval

Post by chivracq » Sat Oct 20, 2018 4:04 am

les_stockton wrote:I don't use imacros every day. The last time I wrote any imacros was probably a year ago. I have to relearn some of it every time I use it.
Yeah, but think a little bit by yourself, you are one of the oldest Forum Users, the Mistakes in your Script are completely "obvious" to spot, even if you haven't used iMacros for 1 year, I would think... :wink:

Hum, first I already told you it's not "Best Practice" (OK, my personal Opinion, but I am pretty "Advanced" I think, and I nearly always find a Solution for all Qt's asked on the Forum, so I would think the "Fundamentals" I use for my "Thinking" must be rather "correct", ah-ah...!) to use 'EVAL()' directly in some other Statement, at least until you've debugged it and you know that it works "correctly"... :idea:

It's fine to use your Syntax but only once you know it works and if "anything goes wrong", you should be able to debug it yourself I would think... => You'll make your "Life" easier if you use some "easier" Syntax that you and everybody will understand and follow and that you'll be able to debug yourself, my Advice... :idea:

(You should follow my "Principles" and "Recommendations" to be honest, when I post stg on the Forum, I know it works because I usually use it myself..., and I always try to use the "easiest" Syntax and Method(s) to achieve some Functionality, just an Idea, ah-ah...! :idea: )

>>>

Back to your Script, you use some '!VAR2' in your 'EVAL()' that you only declare a bit later on in your Script, oops...! :shock: , this is not going to work, ah-ah...! "Who the fuck is '!VAR2'...!?" is going to think the 'EVAL()', I would think..., just saying...! :idea:

Hum, but OK, "although I get a type error on the first pass since !VAR2 isn't set the first time.", re-hum, re-Not-OK, yeah, well, what do you expect then...?

But hum, some "stupid" Qt/Rmk:
You know I hope that the '!LOOP' Var is only read/executed on the first Loop, I hope...? :?
(Its primary Aim is to "avoid' the Header in some '.CSV' DataSource or if you start looping your Script again after it aborted for any Reason, to start again "directly" at Row=101 for example, if your don't want to run the first 100 Rows again...)
(Just saying, I'm a getting a bit "unsure" about your Level of Knowledge of iMacros, because of your 2011-2018 years of "Experience" with iMacros, and some parts in your Script are fairly Advanced while you make some Newbies Mistakes in other parts...) :?

Use 'PROMPT' to follow and debug your Vars, this is the "Basics" for writing (a bit "elaborate") Scripts... :idea:
(Hum, that's one more of my "Recommendations" that you need to follow, ah-ah...! :wink: )
- (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: 7715
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: SET !LOOP from Eval

Post by chivracq » Sat Oct 20, 2018 7:33 pm

Hum, got a bit "excited" about 'EVAL()' and "syntax" in my previous Post, after a long night, ah-ah...! :oops:

But OK, I had another "Look" at your Scenario, but hum, I don't really understand the Logic you want for the 'SET !LOOP', and the 'SET !LOOP' only gets executed on the first Loop (by design)..., and I guess on the first Loop your Col_1 will never be empty, hum, unless you hardcode the '!DATASOURCE_LINE', but even if Col_1 is not empty, '!LOOP' will be undefined as you don't return a Value for the 'ELSE' Condition...

Is "Better Practice" btw to always return a Value for the 'ELSE', even if you don't use it, but that comes in "handy" if you need to debug your Script with 'PROMPT' to follow your Vars... 'EVAL()' Statements with 'IF/ELSE' Conditions "often" behave "unexpectedly", especially with Numbers coming from previous Vars that iMacros and/or 'EVAL()' (at least on FF) tend to treat like Strings, and a "6<8" will (still) return 'TRUE', but "6<10" will return 'FALSE' because of the "10" being treated like a String which starts with a "1" which "alphabetically" is sorted before the "6".
Hum, but OK, you do return a Value for the 'ELSE', got confused by your 'if/else' Syntax that I don't use...

Code: Select all

SET !VAR1 EVAL("var c1='{{!COL1}}'; var z=c1.length; z;")
SET !LOOP EVAL(parseInt("({{!VAR1}}<1)?1:{{!LOOP}}"))
=> Stg like...:

Code: Select all

SET !VAR1 EVAL("var c1='{{!COL1}}'; var z=c1.length; z;")
SET !VAR2 EVAL("var v1='{{!VAR1}}', n='{{!LOOP}}'; var z; if((v1*1))<1){z=n;} else{z=999;}; z;")
SET !LOOP {{!VAR2}}
PROMPT COL1:<SP>_{{!COL1}}_<BR>Length:<SP>{{!VAR1}}<BR><BR>VAR2:<SP>{{!VAR2}}<BR>LOOP:<SP>{{!LOOP}}
Not tested, but even on the 2nd Run (with Col_1 not being empty on Loop=1), '!LOOP' will already =1000, I expect... (And you need to specify some Nb>999 in the 'Loop_Max' Field of course, or the Script will only loop once...)

If Col_1 was empty on Loop=1, '!LOOP' will always =2 on Loop=2 no matter if Col_1 is then empty or not on Loop='!LOOP'=2, because the 'SET !LOOP' will not be executed, iMacros will pull the Value for '!LOOP' from its internal Memory...

But hum, OK, I'm still not "sure' that's the Mechanism that you want... :?

>>>

EDIT: Hum, wait... I made a Mistake..., got confused by your 'if/else' Syntax that I don't use... Yep indeed, not good, ah-ah...! :oops:

OK, 2nd Try...:

Code: Select all

SET !VAR1 EVAL("var c1='{{!COL1}}'; var z=c1.length; z;")
SET !VAR2 EVAL("var v1='{{!VAR1}}', n='{{!LOOP}}'; var z; if((v1*1))<1){z=1;} else{z=n;}; z;")
SET !LOOP {{!VAR2}}
PROMPT COL1:<SP>_{{!COL1}}_<BR>Length:<SP>{{!VAR1}}<BR><BR>VAR2:<SP>{{!VAR2}}<BR>LOOP:<SP>{{!LOOP}}
But this one will always return 1 for the 'SET !LOOP', I would think..., no matter if Col_1 is empty or not on the first Loop. :?

=> Can simply use, which is the Default anyway...:

Code: Select all

SET !LOOP 1
Hum, unless you already had a previous '!SET LOOP' Statement in the same Script..., which would be a bit cumbersome in my Opinion..., and not "Best Practice" I would think...
(Even if hum..., I use it myself as a "Trick" in one of my own Scripts, oops..., but it's meant as a "creative Trick" in a long Script (5000 Lines) with some Calculations based on '!LOOP' (to activate or mute different parts of the whole long Script) where at the end, the Script "decides" by itself if it was "successful" (enough) and/or if it needs to run again and how many times... Hum, and it is also meant as a "Workaround" in that Script for the Lack of a '!LOOP_MAX' Var that I've been asking for several years already, and that I use to display some dynamic Log/Report in the Display Area of the Side Panel only on the last Run..., to confirm the "successful" (final) Run and that alerts me if some further Action(s) is/are needed..., and to be able to implement that Functionality in pure '.iim' without using a '.js' Script...)
- (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...
les_stockton
Posts: 32
Joined: Sun Mar 06, 2011 11:30 pm

Re: SET !LOOP from Eval

Post by les_stockton » Mon Oct 22, 2018 1:19 pm

I finally made progress based on information given here. My very last hurdle seems to be that no matter what I calculate inside the EVAL, I can't actually set !LOOP to that value. I can set it to a constant, such as 1, 2, 3 or 4. but although the EVAL actually returns a value like that, the following statement doesn't actually set !LOOP.

Code: Select all

'SET !LOOP EVAL("var z={{!LOOP}}; var col=\"{{!COL1}}\"; if (col.includes(\"somestring\")){ z=1;};  z;")
I'd like to set !LOOP to a derived value from EVAL.
chivracq
Posts: 7715
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: SET !LOOP from Eval

Post by chivracq » Mon Oct 22, 2018 2:20 pm

les_stockton wrote:I finally made progress based on information given here. My very last hurdle seems to be that no matter what I calculate inside the EVAL, I can't actually set !LOOP to that value. I can set it to a constant, such as 1, 2, 3 or 4. but although the EVAL actually returns a value like that, the following statement doesn't actually set !LOOP.

Code: Select all

'SET !LOOP EVAL("var z={{!LOOP}}; var col=\"{{!COL1}}\"; if (col.includes(\"somestring\")){ z=1;};  z;")
I'd like to set !LOOP to a derived value from EVAL.
Ah OK, good, I was "wondering" if you had made some Progress, ah-ah...! :wink:

Yep you can use 'EVAL()' to define the Start '!LOOP', but it doesn't really make sense to base '!LOOP' on itself because the 'SET !LOOP' Statement only gets executed on the first Run and at that moment, your "var z='{{!LOOP}}'" =1. (Single Quotes or Escaped Double Quotes are missing btw in your Var Declaration...)

Like I already said in my "2nd Try" in my last Post, all 'EVAL()' Statements you've tried to use until now will all return 1 for both Conditions, which is already the Default...

But maybe if you gave more Details about your "whole Scenario" and the Logic that you want, I would understand better and I would probably find you a simpler Solution... :idea:
- (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...
les_stockton
Posts: 32
Joined: Sun Mar 06, 2011 11:30 pm

Re: SET !LOOP from Eval

Post by les_stockton » Mon Oct 22, 2018 2:31 pm

I just want it to start back at the first line of the datasource. I guess I need to base that off of a counter, rather than off of !Loop.

Thanks.
chivracq
Posts: 7715
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: SET !LOOP from Eval

Post by chivracq » Mon Oct 22, 2018 2:55 pm

les_stockton wrote:I just want it to start back at the first line of the datasource. I guess I need to base that off of a counter, rather than off of !Loop.

Thanks.
Yeah, then don't use...:

Code: Select all

SET !DATASOURCE_LINE {{!LOOP}}
... but use your own Var (or "Counter" like you call it) instead..., that can be computed using 'EVAL()', and can even be based on '!LOOP' eventually, (like "Nested Loops" with 'Modulo[n]' for example), but don't use the "raw" '!LOOP'...
- (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...
Post Reply