Function Optional_Param_Example(Optional ByVal vOptionalText1 As Variant, Optional ByVal sOptionalText2 As String)
' ---------------------------------------------------------------
' Written By Shanmuga Sundara Raman for http://vbadud.blogspot.com
' ---------------------------------------------------------------
If IsMissing(vOptionalText1) Then
MsgBox "Optional Parameter 1 Missing.."
Else
MsgBox "Optional Parameter 1 Present.."
End If
IsMissing does not work on simple data types (such as Integer or Double) because, unlike Variants, they don't have a provision for a "missing" flag bit.
sOptionalText2 is not reported missing if it is not supplied
If IsMissing(sOptionalText2) Then
MsgBox "Optional Parameter 2 Missing.."
Else
MsgBox "Optional Parameter 2 Present.."
End If
' IsMissing Function, Optional Parameters, IsMissing Doesn't Work
End Function
Sunday, April 08, 2007
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.
I was going crazy with the use of Ismissing with string type parameters. It really only works with variant types.
ReplyDeleteThank you for your explanation. I have saved so much time.
Greetings from Spain...