Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. 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