Page 1 of 1

nested loop issue

Posted: Fri Oct 27, 2017 2:06 am
by green.pine
Code: Select all
Imacros v8.9.7 on FF ver 55.0.3 32-bit, Win 7 32


I am experimenting with simple loop to add another loop inside, but somehow it does not work the way it should,
so anyone willing to help me?

here is the simple loop, that pulls keywords from a csv file, and loop it until the end of keywords from csv file, which works fine,

Code: Select all
var macro = "";
macro +=  "CODE:";
macro +=  "VERSION BUILD=8970419 RECORDER=FX" + "\n";
macro +=  "TAB T=1" + "\n";
macro +=  "SET !EXTRACT NULL" + "\n";
macro +=  "SET !ERRORIGNORE YES" + "\n";
macro +=  "SET !EXTRACT_TEST_POPUP NO" + "\n";
macro +=  "SET !ERRORCONTINUE YES" + "\n";
macro +=  "SET !DATASOURCE keywords-4.csv" + "\n";
macro +=  "SET !DATASOURCE_COLUMNS 1" + "\n";
macro +=  "SET !DATASOURCE_LINE {{LOOPNUM}} " + "\n";
macro +=  "URL GOTO=https://www.google.com/" + "\n";
macro +=  "TAG POS=1 TYPE=INPUT:TEXT FORM=ID:tsf ATTR=ID:lst-ib CONTENT={{!COL1}}" + "\n";
macro +=  "TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:tsf ATTR=NAME:btnK" + "\n";


for(var loop=1;loop<85;loop++)
{
iimSet("LOOPNUM",loop)
iimPlay(macro);
}


I want to add another loop inside, when this main macro runs for say 5 times,( used 5 keywords) another macro (macro2) runs once, and this loop should continues until the end of keywords.

one of the variation I have done:

Code: Select all
var macro = "";
macro +=  "CODE:";
macro +=  "VERSION BUILD=8970419 RECORDER=FX" + "\n";
macro +=  "TAB T=1" + "\n";
macro +=  "SET !EXTRACT NULL" + "\n";
macro +=  "SET !ERRORIGNORE YES" + "\n";
macro +=  "SET !EXTRACT_TEST_POPUP NO" + "\n";
macro +=  "SET !ERRORCONTINUE YES" + "\n";
macro +=  "SET !DATASOURCE keywords-4.csv" + "\n";
macro +=  "SET !DATASOURCE_COLUMNS 1" + "\n";
macro +=  "SET !DATASOURCE_LINE {{LOOPNUM}} " + "\n";
macro +=  "URL GOTO=https://www.google.com/" + "\n";
macro +=  "TAG POS=1 TYPE=INPUT:TEXT FORM=ID:tsf ATTR=ID:lst-ib CONTENT={{!COL1}}" + "\n";
macro +=  "TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:tsf ATTR=NAME:btnK" + "\n";
for(var loop=1;loop<85;)
{
iimSet("LOOPNUM",loop)
iimPlay(macro);
var M = 0
var M =iimPlay(macro)
while (M >=5);
do
{
   iimSet("M",M)
   iimPlay ("macro2");
   
    if (M <3);
      break;
         }
         
 while(true)
      {
       iimSet("M",M);
      iimPlay("macro2");
      M++
      }

loop++
}


this plays macro2 every time macro runs, and somehow the main macro works strangely;

I use javascript because i use another macro, so it is simpler to handle couple of macro files,

appreciate your help;

Re: nested loop issue

Posted: Fri Oct 27, 2017 8:54 am
by chivracq
green.pine wrote:
Code: Select all
Imacros v8.9.7 on FF ver 55.0.3 32-bit, Win 7 32


I am experimenting with simple loop to add another loop inside, but somehow it does not work the way it should,
so anyone willing to help me?

here is the simple loop, that pulls keywords from a csv file, and loop it until the end of keywords from csv file, which works fine,

Code: Select all
var macro = "";
macro +=  "CODE:";
macro +=  "VERSION BUILD=8970419 RECORDER=FX" + "\n";
macro +=  "TAB T=1" + "\n";
macro +=  "SET !EXTRACT NULL" + "\n";
macro +=  "SET !ERRORIGNORE YES" + "\n";
macro +=  "SET !EXTRACT_TEST_POPUP NO" + "\n";
macro +=  "SET !ERRORCONTINUE YES" + "\n";
macro +=  "SET !DATASOURCE keywords-4.csv" + "\n";
macro +=  "SET !DATASOURCE_COLUMNS 1" + "\n";
macro +=  "SET !DATASOURCE_LINE {{LOOPNUM}} " + "\n";
macro +=  "URL GOTO=https://www.google.com/" + "\n";
macro +=  "TAG POS=1 TYPE=INPUT:TEXT FORM=ID:tsf ATTR=ID:lst-ib CONTENT={{!COL1}}" + "\n";
macro +=  "TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:tsf ATTR=NAME:btnK" + "\n";


for(var loop=1;loop<85;loop++)
{
iimSet("LOOPNUM",loop)
iimPlay(macro);
}


I want to add another loop inside, when this main macro runs for say 5 times,( used 5 keywords) another macro (macro2) runs once, and this loop should continues until the end of keywords.

one of the variation I have done:

Code: Select all
var macro = "";
macro +=  "CODE:";
macro +=  "VERSION BUILD=8970419 RECORDER=FX" + "\n";
macro +=  "TAB T=1" + "\n";
macro +=  "SET !EXTRACT NULL" + "\n";
macro +=  "SET !ERRORIGNORE YES" + "\n";
macro +=  "SET !EXTRACT_TEST_POPUP NO" + "\n";
macro +=  "SET !ERRORCONTINUE YES" + "\n";
macro +=  "SET !DATASOURCE keywords-4.csv" + "\n";
macro +=  "SET !DATASOURCE_COLUMNS 1" + "\n";
macro +=  "SET !DATASOURCE_LINE {{LOOPNUM}} " + "\n";
macro +=  "URL GOTO=https://www.google.com/" + "\n";
macro +=  "TAG POS=1 TYPE=INPUT:TEXT FORM=ID:tsf ATTR=ID:lst-ib CONTENT={{!COL1}}" + "\n";
macro +=  "TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:tsf ATTR=NAME:btnK" + "\n";
for(var loop=1;loop<85;)
{
iimSet("LOOPNUM",loop)
iimPlay(macro);
var M = 0
var M =iimPlay(macro)
while (M >=5);
do
{
   iimSet("M",M)
   iimPlay ("macro2");
   
    if (M <3);
      break;
         }
         
 while(true)
      {
       iimSet("M",M);
      iimPlay("macro2");
      M++
      }

loop++
}


this plays macro2 every time macro runs, and somehow the main macro works strangely;

I use javascript because i use another macro, so it is simpler to handle couple of macro files,

appreciate your help;

So..., OK, you prefer to go to go the '.js' way after all, fair enough..., I guess I probably was the first User, and for a long time the only one as well, to do Nested Loops in pure '.iim', but a '.js' Script is the "Standard" way anyway..., :wink:
But hum, I don't do '.js' Scripts, so I won't really be able to help you... Other Advanced User @iimfun had posted some "clean and easy" 'for + for' Example of Nested Loops in the following Thread that you can maybe try to reuse/adapt but your 'for + while + while' Implementation looks already more complex to me...

Mini-Remark: Your '!ERRORCONTINUE' Statement is useless as this Command was deprecated several years ago, and your 'SET !EXTRACT NULL' at the beginning of your Macro as well as '!EXTRACT' already gets reset when launching a Macro. The place for 'SET !EXTRACT NULL' is just before or just after an 'EXTRACT', not at the beginning of a Script...

For your Qt, you may want to follow some very similar Thread that I noticed on SOF about 1 week ago, let me see if I can find it back... Yep, here it is...:
- Imacros/javascript How to make 2 loop macros work together? nested loop
Hum, still no Reply in that Thread, but ah-ah...!, I notice the same "weird" Lines about '!ERRORCONTINUE' and '!EXTRACT', so I guess this Thread was already yours, ah-ah...! Hum, FCI not mentioned there, I don't upvote it... :wink: