How to correctly use loop

2019-09-11 07:34发布

问题:

I have macros that invites friends to FB groups, friends name is taken from CSV file, so i need write loop, than will invites all people from csv file . Here is my macros

var macro,start;
macro =  "CODE:";
macro +=  "SET !ERRORIGNORE YES" + "\n"; 
macro +=  "SET !EXTRACT_TEST_POPUP NO" + "\n"; 
macro +=  "SET !DATASOURCE FB<SP>Groups.csv" + "\n"; 
macro +=  "SET !DATASOURCE_COLUMNS 1000" + "\n"; 
macro +=  "SET !LOOP 1" + "\n"; 
macro +=  "SET !DATASOURCE_LINE {{!LOOP}}" + "\n"; 
macro +=  "URL GOTO=" + "\n"; 
macro +=  "TAG POS=1 TYPE=I ATTR=CLASS:" + "\n"; 

So i think from here must starts loop

macro +=  "TAG POS=2 TYPE=SPAN ATTR=TXT:Invite<SP>Friends" + "\n"; 
macro +=  "SET !DATASOURCE FB<SP>Users.csv" + "\n"; 
macro +=  "SET !DATASOURCE_COLUMNS 1000" + "\n"; 
macro +=  "SET !LOOP 1" + "\n"; 
macro +=  "SET !DATASOURCE_LINE {{!LOOP}}" + "\n"; 
macro +=  "TAG POS=1 TYPE=INPUT:TEXT ATTR=CLASS:" + "\n"; 
macro +=  "TAG POS=1 TYPE=SPAN ATTR=CLASS:uiButtonText" + "\n"; 
iimPlay(macro)

回答1:

Play with this snippet:

var macro = "CODE:";
for (i = 1; i <= 3; i++) {
    macro +=  "SET !DATASOURCE FB<SP>Users.csv" + "\n"; 
    macro +=  "SET !DATASOURCE_LINE " + i + "\n"; 
    macro +=  "PROMPT {{!COL1}}" + "\n"; 
    iimPlay(macro);
}

Hope, you can catch the idea.


Here is a way of how to define the number of rows in your csv-file:

var numRows = 0;
while (true) {
    var macro = "SET !DATASOURCE FB<SP>Users.csv" + "\n"; 
    macro += "SET !DATASOURCE_LINE " + (numRows + 1) + "\n"; 
    if (iimPlayCode(macro) == 1)
        numRows++;  
    else
        break;
}
alert(numRows);


标签: imacros