Optional Keyword (1 Viewer)

doulostheou

Registered User.
Local time
Today, 04:57
Joined
Feb 8, 2002
Messages
314
A friend of mine was trying to use the optional keyword in his function. I don't have any experience with it, so I was wondering if anyone could give him any advise on where he is going wrong. His syntax is something like below.

Function Test(x as Date, Optional y as Boolean)
If isMissing(y) Then
....
ElseIf y = true Then
....
Else
....
End If

Apparently, isMissing(y) never evaluates as true, even when he calls the function without a y variable.

Thanks in advance.
 

Alexandre

Registered User.
Local time
Today, 16:57
Joined
Feb 22, 2001
Messages
794
Only variants can (eventually) be evaluated to 'missing'. For other data types, you will have to define a default value and do some good old checking:

Function Test(x as Date, Optional y as Boolean = False)
If Not y Then ...

Or (less efficient, but if you really need to...)
Function Test(x as Date, Optional vary as Variant= False)
If isMissing(vary) Then ...
 
Last edited:

doulostheou

Registered User.
Local time
Today, 04:57
Joined
Feb 8, 2002
Messages
314
Thanks. That's exactly what he needed to know.
 

Users who are viewing this thread

Top Bottom