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: 
Not applicable

Optional Argument in Sub or Function

Using QV10 SR3.  Can you create a Function or Sub with an optional argument?  For example, can I create a Function like:

Function AddEmUp (a, b, optional c)

  AddEmUp = a + b + c

End Function

Here, the argument c is optional...so it works if I pass it two or three arguments.

2 Replies
swuehl
MVP
MVP

You can create a function variable (dollar sign expansion with arguments), e.g.

Define in the script:

Set vDateDiff = if(len($2)=0, today(), $2) - $1;

Then you can call vDateDiff with one or two arguments (second argument defaults to today()):

=$(vDateDiff('1/1/2012'))

=$(vDateDiff('1/1/2012','2/1/2012'))

IAMDV
Luminary Alumni
Luminary Alumni