Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

if statement question

This is seemingly simple but is causing me headache:

I have a variable which can be empty or have a value, i.e.

set myvar = ;

or

set marvar = 1;

I'm assuming that elsewhere I can test

if '$(myvar)' then or if isnull('$(myvar)') then

but this isn't working. I've tried many ways but didn't find a solution. I get an error message "script line error if ... then". $(#myvar) crashes script without any error.

On top of that putting msgbox('$(ScriptErrorDetails)') doesn't work, MsgBox isn't recoginzed in the script.

I have a feeling that I'm missing something very basic. Any thoughts?

2 Replies
amars
Specialist
Specialist

Try

if Trim('$(myvar)') = '' or isnull('$(myvar)') then

prieper
Master II
Master II

Normally you do not need the apostrophs, they are only needed when explicitly you need to declare a string. Within the normal statements in the script you also do not need to use the $(...), just the name should do it. Thus your statement should read

IF myvar = 1 THEN ... ELSE ... END IF


n.b.: If you can avoid it, would not have a variable containing NULL-value. It is better to have it reading either 0 or 1.

HTH
Peter