Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

switch case - If...else problem

hi

attached its an example of my problem....

why its stopping in the else inside case 1??

1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

It's a little bit of an oddity as to how the script interpretation and execution flows.

You are triggering Case 2. The statements in Case 1 do not get executed, but they do get expanded and syntax checked.

The variable _vFileExists never get intialized (the LET doesn't get executed) so the IF statement that references it gets expanded to:

"IF =0 THEN"

which is invalid (not trapped until the ELSE).

You can fix the problem by initializing the variable before the SWITCH.

LET _vFileExists = 0;

or code the IF statement to tolerate an empty variable by including quotes.

IF '$(_vFileExists)'=0 THEN

-Rob

http://masterssummit.com

View solution in original post

3 Replies
Not applicable
Author

Try with this script:

Let _vAction=1;

SWITCH $(_vAction)

CASE 1

  LET _vFileName = 'xxxx';

  LET _vFileNameD = '$(_vFileName)'&'.qvd';

  LET _vFileExists = if(FileSize('$(_vFileNameD)') > 0, -1, 0);

  SWITCH $(_vFileExists)

  CASE 0

  LET _vText1='stops here';

  CASE

  LET _vText1='why stop here??';

  ENDSWITCH

CASE 2

  LET _vText='Case 2';

  let _vText1='win!!';

ENDSWITCH

maxgro
MVP
MVP

replace

IF $(_vFileExists)=0 THEN

with

IF ($(_vFileExists)=0) THEN

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

It's a little bit of an oddity as to how the script interpretation and execution flows.

You are triggering Case 2. The statements in Case 1 do not get executed, but they do get expanded and syntax checked.

The variable _vFileExists never get intialized (the LET doesn't get executed) so the IF statement that references it gets expanded to:

"IF =0 THEN"

which is invalid (not trapped until the ELSE).

You can fix the problem by initializing the variable before the SWITCH.

LET _vFileExists = 0;

or code the IF statement to tolerate an empty variable by including quotes.

IF '$(_vFileExists)'=0 THEN

-Rob

http://masterssummit.com