-
HI there,
I have a function in VB which has 2 optional parameters. How can I find out whether the parameter was set or not.
Regards,
Radhika
-
Use the IsMissing Function:
Dim ReturnValue
' The following statements call the user-defined function procedure.
ReturnValue = ReturnTwice() ' Returns Null.
ReturnValue = ReturnTwice(2) ' Returns 4.
' Function procedure definition.
Function ReturnTwice(Optional A)
If IsMissing(A) Then
' If argument is missing, return a Null.
ReturnTwice = Null
Else
' If argument is present, return twice the value.
ReturnTwice = A * 2
End If
End Function
-
The following example demonstrates how you can set a default value for an argument. For example, if nothing is entered in Param2, then it will be 12.
Code:
Function MyFunc(ByVal Param1 As Long, Optional ByVal Param2 As Long = 12) As Long
End Function
-
Thanks
Thanks it worked.
Radhika