Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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
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;
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
I don't get exactly your reqourment. Can you share more detailed code, Jörgen?
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
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
I think I understand your work-around. And that should work indeed.
I'll test this.
Many thanks.
Greetings,
Jörgen