Nested Loops in 2 macros

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.

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.

Nested Loops in 2 macros

by a2515125 on Fri Mar 03, 2017 11:37 am

Windows 10/ FF51.0.1 /iMacros 8.9.7



hey,

after reading some "nested loop" thread from this thread

I try to write my own one script in js but failed

I cannot find the fault so come up here again for help(I believe something is wrong in EVAL sentence :oops: )

it said : can not parse macro line: CODE:SET i EVAL("z="{{!LOOP}}";z = (z % 3);if(z == 0){ z = 3};z=z++;") (Error code: -910)


my purpose is to run

macro1 1 time (go to url page=1,2,3,4,5,6....,n)

and then run macro2 15times

and Loop (macro1 + macro2) (go next url page to run again)

here is my .js code

Code: Select all
var macro1,macro2,z;

macro1 = "CODE:";
macro1 += "SET !ERRORIGNORE YES" + "\n";
macro1 += "URL GOTO=https://tw.carousell.com/kyaralin/followers/?page={{!LOOP}}" + "\n";

macro2 = "CODE:";
macro2 += 'SET i EVAL("z=\"{{!LOOP}}\";z = (z % 3);if(z == 0){ z = 3};z=z++;")' + "\n";

macro2 += "TAG POS={{i}} TYPE=BUTTON ATTR=TXT:追蹤" + "\n";

iimPlayCode(macro2);

for (i=1; i<=15; i++ ){

iimSet("i", i);
iimPlayCode(macro2);

}
a2515125
 
Posts: 84
Joined: Mon Dec 05, 2016 8:37 pm

Re: Nested Loops in 2 macros

by a2515125 on Sun Mar 05, 2017 6:49 pm

i try to use another way to separate .iim into two .iim and use .js to Loop

(macro1.iim+macro2.iim with .js to count)

however, the macro2.iim (go to page cannot do loop) keep reloading page=1 when I run .js

it works well when run in .iim but does not work in .js. I do not know why?

also i have no idea to express macro1 run 15times and then macro2 1time

and Loop macro1+macro2 in .js



any suggestion would be appreciated :idea:

macro1
Code: Select all
VERSION BUILD=8970419 RECORDER=FX

SET !EXTRACT_TEST_POPUP NO
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0

TAB T=1
'set loop to PRESS'

SET !VAR1 EVAL("var z=\"{{!LOOP}}\";z = (z % 3);if(z == 0){ z = 3};z=z++;")

TAG POS={{!VAR1}} TYPE=BUTTON ATTR=TXT:追蹤




macro2
Code: Select all
VERSION BUILD=8970419 RECORDER=FX

SET !EXTRACT_TEST_POPUP NO
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0
URL GOTO=https://tw.carousell.com/kyaralin/followers/?page={{!LOOP}}



js
Code: Select all


var i;
for (i =0 ; i <16; i++)
{
iimSet("i", i);
iimPlay("macro1.iim")
}


var j;
for (j =0 ; j <5; j++)
{
iimSet("j", j);
iimPlay("macro2.iim")
}
a2515125
 
Posts: 84
Joined: Mon Dec 05, 2016 8:37 pm

Re: Nested Loops in 2 macros

by chivracq on Sun Mar 05, 2017 10:40 pm

a2515125 wrote:Windows 10/ FF51.0.1 /iMacros 8.9.7

hey,

after reading some "nested loop" thread from this thread

I try to write my own one script in js but failed

I cannot find the fault so come up here again for help(I believe something is wrong in EVAL sentence :oops: )

it said : can not parse macro line:
Code: Select all
CODE:SET i EVAL("z="{{!LOOP}}";z = (z % 3);if(z == 0){ z = 3};z=z++;")
(Error code: -910)


my purpose is to run

macro1 1 time (go to url page=1,2,3,4,5,6....,n)

and then run macro2 15times

and Loop (macro1 + macro2) (go next url page to run again)

here is my .js code

Code: Select all
var macro1,macro2,z;

macro1 = "CODE:";
macro1 += "SET !ERRORIGNORE YES" + "\n";
macro1 += "URL GOTO=https://tw.carousell.com/kyaralin/followers/?page={{!LOOP}}" + "\n";

macro2 = "CODE:";
macro2 += 'SET i EVAL("z=\"{{!LOOP}}\";z = (z % 3);if(z == 0){ z = 3};z=z++;")' + "\n";

macro2 += "TAG POS={{i}} TYPE=BUTTON ATTR=TXT:追蹤" + "\n";

iimPlayCode(macro2);

for (i=1; i<=15; i++ ){

iimSet("i", i);
iimPlayCode(macro2);

}


a2515125 wrote:i try to use another way to separate .iim into two .iim and use .js to Loop

(macro1.iim+macro2.iim with .js to count)

however, the macro2.iim (go to page cannot do loop) keep reloading page=1 when I run .js

it works well when run in .iim but does not work in .js. I do not know why?

also i have no idea to express macro1 run 15times and then macro2 1time

and Loop macro1+macro2 in .js

any suggestion would be appreciated :idea:

macro1
Code: Select all
VERSION BUILD=8970419 RECORDER=FX

SET !EXTRACT_TEST_POPUP NO
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0

TAB T=1
'set loop to PRESS'

SET !VAR1 EVAL("var z=\"{{!LOOP}}\";z = (z % 3);if(z == 0){ z = 3};z=z++;")

TAG POS={{!VAR1}} TYPE=BUTTON ATTR=TXT:追蹤


macro2
Code: Select all
VERSION BUILD=8970419 RECORDER=FX

SET !EXTRACT_TEST_POPUP NO
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0
URL GOTO=https://tw.carousell.com/kyaralin/followers/?page={{!LOOP}}



js
Code: Select all


var i;
for (i =0 ; i <16; i++)
{
iimSet("i", i);
iimPlay("macro1.iim")
}


var j;
for (j =0 ; j <5; j++)
{
iimSet("j", j);
iimPlay("macro2.iim")
}

Quick look after your 2nd Post, you were calling twice 'macro2' in your first Post, seems OK now in your 2nd Post, but HUM-HUM-HUM...!, I cannot find a good Explanation/Justification for using an 'EVAL()' Statement in some on-the-fly '.iim' Created Macro in a '.js' Script, sorry, convince me...!

The Purpose of 'EVAL()' is to be able to use JavaScript for some Data Manipulation from inside an '.iim' Script, but if you are using a '.js' Script, do that Data Manipulation directly from your '.js' Script instead of "double nesting" it in an '.iim' Script...! :idea: :roll:

But if you still go your way, Pb are the Double Quotes that already need to be escaped in 'EVAL()' in an '.iim' + escaped as well in a '.js' Script => double/triple/quadruple escaped in your cumbersome Construction...! Well, good luck...!
- (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: 6490
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Nested Loops in 2 macros

by a2515125 on Mon Mar 06, 2017 3:14 am

thanks

I solved the pb after 10 hours trying.

I use two macro.iim and do nested loop in .js

but I would like to know if how to write in pure .iim & pure .js or simple script


Code: Select all





var j;
   for (j =0 ; j <99999; j++){
      iimSet("j", j);
      iimPlay("macro2.iim")


var i;
   for (i =0 ; i <16; i++){
      iimSet("i", i);
      iimPlay("macro1.iim")
     
    }
}



a2515125
 
Posts: 84
Joined: Mon Dec 05, 2016 8:37 pm

Re: Nested Loops in 2 macros

by chivracq on Mon Mar 06, 2017 10:44 am

a2515125 wrote:thanks

I solved the pb after 10 hours trying.

I use two macro.iim and do nested loop in .js

but I would like to know if how to write in pure .iim & pure .js or simple script
Code: Select all
var j;
   for (j =0 ; j <99999; j++){
      iimSet("j", j);
      iimPlay("macro2.iim")

var i;
   for (i =0 ; i <16; i++){
      iimSet("i", i);
      iimPlay("macro1.iim")
     
    }
}

Yep, then simply declare your 'macro1' and 'macro2' like @iimfun did in his Example that you referred to in your OP...

And if you want to do it in pure '.iim', which I think would indeed be easier, as the Nested Looping only requires one 'EVAL()' Statement Modulo[15] for the 'URL GOTO' and you had already produced/found an Example of such a Statement with Modulo[3] in your Example in:
Code: Select all
SET i EVAL("z="{{!LOOP}}";z = (z % 3);if(z == 0){ z = 3};z=z++;")
(Even if that Example contains some Syntax Error(s), check again where you got if from but you must have made some Mistake copying/adapting it... Oh...!, but you had it correct in your OP...)

That will give stg like:
Code: Select all
VERSION BUILD=8820413 RECORDER=FX
TAB T=1
SET !ERRORIGNORE YES
SET Modulo 15
SET URL_Site https://tw.carousell.com/kyaralin/followers/?page=
SET No_URL ""
SET URL_Page EVAL("var n='{{!LOOP}}', m='{{Modulo}}', us='{{URL_Site}}', nu='{{No_URL}}'; var x,y,z; x=Math.ceil(n/m);  y=(n%m); if(y==1){z=us+x;} else{z=nu;}; z;")
PROMPT LOOP:<SP>_{{!LOOP}}_<BR>_{{URL_Page}}_
URL GOTO={{URL_Page}}
(Tested on iMacros for FF v8.8.2, PM v26.3.3 (=FF47), Win10-x64.)
- (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: 6490
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Nested Loops in 2 macros

by a2515125 on Mon Mar 13, 2017 10:26 pm

thanks for your help :))

I will try to use pure iim if possible
a2515125
 
Posts: 84
Joined: Mon Dec 05, 2016 8:37 pm


Return to General Support & Discussions

Who is online

Users browsing this forum: No registered users and 11 guests

-->