Reputation: 1740
I want to get the number of row count of a csv file and use that count as a variable in a loop. Is it possible to achieve using imacros script. This post shows a code in javascript. This is what I want to do
for(j=1;j<=**row_count**;j++){
iimSet('lineNumber', j);
iimPlay("MyFolder//checkRecord_IfExist.iim");
getData = iimGetLastExtract();
I want the number to be used in the variable row_count
I tried code in .js file from the reference post but this gives me error
ReferenceError: imns is not defined, line 15 (Error code: -991)
Does any one has any idea about how should it be done. Any help would be much appreciated. Thanks
Upvotes: 0
Views: 1059
Reputation: 116
It's not possible to get the row count directly from iMacros, but it's not necessary in order to loop through all the rows in your input file. The macro will return error -951 whenever you attempt to read past the end of the file (in other words, when !DATASOURCE_LINE exceeds the number of rows in the file). So you can simply check the return value of iimPlay for this value to determine when to stop looping. For example:
const EOF = -951;
var moreRows = true;
var row = 1;
var ret;
while (moreRows)
{
iimSet('lineNumber', row);
ret = iimPlay("MyFolder//checkRecord_IfExist.iim");
if (ret == EOF) {
moreRows = false;
}
else {
getData = iimGetLastExtract();
row++;
}
}
Upvotes: 1