Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
debutler
Contributor
Contributor

Next inside and If Then

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

1 Solution

Accepted Solutions
Peter_Cammaert
Partner - Champion III
Partner - Champion III

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

View solution in original post

6 Replies
anbu1984
Master III
Master III

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

jagan
Luminary Alumni
Luminary Alumni

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

Peter_Cammaert
Partner - Champion III
Partner - Champion III

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

debutler
Contributor
Contributor
Author

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.

anbu1984
Master III
Master III

Next clause comes with For each control statement. You cannot use Next alone to skip the loop.

Peter_Cammaert
Partner - Champion III
Partner - Champion III

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...