Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
debutler
New 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

Re: Next inside and If Then

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

6 Replies
anbu1984
Honored Contributor III

Re: Next inside and If Then

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

MVP
MVP

Re: Next inside and If Then

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

Re: Next inside and If Then

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
New Contributor

Re: Next inside and If Then

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
Honored Contributor III

Re: Next inside and If Then

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

Re: Next inside and If Then

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

Community Browser