Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I need to cycle through a bunch of files being generated by another program.
If the file is empty I need to skip to the next file.
I am getting a script error on the next inside of the if statement.
Any ideas. If you comment out the if statement this works. If you remove the next and add other logic this works.
for Each v_file in a.qvd, b.qvd, c.qvd
Let vQVDExists = if(FileSize(v_file) > 0, -1, 0);
IF $(vQVDExists)=0 THEN
next
END IF;
// Do load of file here
next
Or if you do not want to read the data from empty files:
FOR Each v_file IN a.qvd, b.qvd, c.qvd
IF FileSize($(v_file)) > 0 THEN
LOAD
*
FROM v_file;
END IF;
NEXT
for Each v_file in a.qvd, b.qvd, c.qvd
Let vQVDExists = if(FileSize(v_file) > 0, -1, 0);
IF $(vQVDExists)<>0 THEN
// Do load of file here
END IF;
next
Hi,
Try like this
for Each v_file in a.qvd, b.qvd, c.qvd
IF FileSize($(v_file)) = 0 THEN
LOAD
*
FROM v_file;
END IF;
next
Or if you do not want to read the data from empty files:
FOR Each v_file IN a.qvd, b.qvd, c.qvd
IF FileSize($(v_file)) > 0 THEN
LOAD
*
FROM v_file;
END IF;
NEXT
Reversing the logic so I do not need the NEXT inside the if will work for this problem.
However it still doesn't explain why you can not use NEXT inside an IF statement.
I am curious to know if NEXT is not allowed or do I have some semantic issue I am missing to make that work.
Thanks for all the helpful responses.
Next clause comes with For each control statement. You cannot use Next alone to skip the loop.
Indeed.
NEXT is the FOR loop terminator and signals the semantic end of the FOR loop.
Exiting the FOR loop can be accomplished by specifying EXIT FOR; somewhere in the body of the FOR loop.
However, in VBScript there is no statement that prematurely skips the FOR body code in order to continue with the next iteration, as CONTINUE FOR does in Visual Basic.
It's all to be done using IF THEN ELSE logic...