Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
jepeerik
Contributor III
Contributor III

Sub from Include not found when Call is outside IF-statement

I want to Include a file containing a Sub. I include this within an IF-statement.

When the Call-statement is executed within the IF-statement, the Sub if found and executed. When the Call is outside the IF-statement, the Call is giving an error saying that the Sub is not found.

I've tested it with an Include and Must_Include.

Any clue?

Script for loading the Include file and the IF and Call statements:

IF 1=0 THEN

            TRACE 'Test IF';

ELSE

            TRACE 'Test ELSE';

$(Include=lib://FolderQlik\TestInclude.qvs);

Call TestInclude;               //This Call is working fine

END IF

TRACE 'Test outside IF';

Call TestInclude;                         //This Call is generating an error

Contents of the Include file:

TRACE 'preSUB TestInclude';

SUB TestInclude

            TRACE 'SUB TestInclude';

END SUB

Sharing knowledge increases your knowledge
1 Solution

Accepted Solutions
8 Replies
jepeerik
Contributor III
Contributor III
Author

Thanks Andrey for your response.

Now I know why it isn't working. I also noticed this behaviour with the FOR-loop.

So, the reason why I actually want to do this is because I dynamically want to Include all QVS-files (except 1, so therefore the IF-statement) within a folder and therefore I need a FOR-loop. So that will not work this way.

Maybe you have another solution?

Thanks.

Greetings,

Jörgen

Sharing knowledge increases your knowledge
andrey_krylov
Specialist
Specialist

Hi, Jörgen. Maybe, for dynamical Include - something like this

IF 1=0 THEN

           TRACE 'Test IF';

            vScript = '';

ELSE

            TRACE 'Test ELSE';

vScript = 'Include=lib://FolderQlik\TestInclude.qvs';

$($(vScript));

Call TestInclude;               //This Call is working fine

END IF

TRACE 'Test outside IF';

$($(vScript));

Call TestInclude;    

jepeerik
Contributor III
Contributor III
Author

Thanks. That's indeed the trick to get it outside the IF-statement.

But I'm stuck with the FOR-loop. I need a loop to dynamically load all qvs files from a folder, and as far as I know that's something I can't fix without the loop or outside the loop.

Greetings,

Jörgen

Sharing knowledge increases your knowledge
andrey_krylov
Specialist
Specialist

I don't get exactly your reqourment. Can you share more detailed code, Jörgen?

jepeerik
Contributor III
Contributor III
Author

I have several qvs files in a folder and I want to Include them all, except for 1 (@Calls.qvs).

I want to do this dynamically, because I've got a lot of folders with different qvs files.

These qvs files containing SUB routines. After Including all those files, I want to Call those routines on another place.

Underneath my code to Include those files. This is working fine, but the as discussed before, I can't Call a subroutine outside the IF statement and/or FOR loop.

For the IF-statement we've got a workaround. Now I need the work around for the FOR loop.

//Load each qvs file in the app folder, excluding @Calls.qvs

FOR EACH vIncludeFile in FILELIST('$(vFolder)*.qvs');

      IF '$(vIncludeFile)' = REPLACE('$(vFolder)@Calls.qvs','\','/') THEN

          //Do Nothing

      ELSE

           $(Must_Include=$(vIncludeFile));

      END IF

NEXT vIncludeFile

CALL SubRoutineFromQVS          //which is failing

Sharing knowledge increases your knowledge
andrey_krylov
Specialist
Specialist

Oh, Maybe this

vString = '';

FOR EACH vIncludeFile in FILELIST('$(vFolder)*.qvs');

      IF '$(vIncludeFile)' = REPLACE('$(vFolder)@Calls.qvs','\','/') THEN

          //Do Nothing

      ELSE

//           $(Must_Include=$(vIncludeFile));

          vString = vString & '$'&'(Must_Include=$(vIncludeFile));';

      END IF

NEXT vIncludeFile

$(vString);

CALL SubRoutineFromQVS 

jepeerik
Contributor III
Contributor III
Author

I think I understand your work-around. And that should work indeed.

I'll test this.

Many thanks.

Greetings,

Jörgen

Sharing knowledge increases your knowledge