Results 1 to 4 of 4

Thread: How to check whether an optional parameter to a function was set

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    15

    Exclamation

    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

  2. #2
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    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
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  3. #3
    Guest
    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    15

    Smile Thanks

    Thanks it worked.

    Radhika

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width