How to correctly use loop

不打扰是莪最后的温柔 提交于 2019-12-12 03:24:47

问题


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);


来源:https://stackoverflow.com/questions/32922704/how-to-correctly-use-loop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!