CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009
    Posts
    7

    VB6 Functions: Optional Parameters

    How do I test for the presence of an option parameter with a function?

    Example

    Public Sub GridWrite(Grid As Control, FileName As String, Optional AnyForm As Form)

    I want to see if the optional parameter "Anyform" was given by the calling form.

    I tried:
    if AnyForm.Name>"" then
    ' statements when parameter is given
    endif

    but I get an error 91: Object variable or With block variable not set.

    Same thing with:
    if AnyForm >'' then

    If the optional parameter is an Integer, then a zero is given but when the parameter is a form, I get the error.

    Thanks for your help

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: VB6 Functions: Optional Parameters

    You should rather check for Nothing. Something like this
    Code:
    Public Sub GridWrite(Grid As Control, FileName As String, Optional AnyForm As Form)
    
    If Not AnyForm Is Nothing Then
          'AnyForm was passed from the calling function
    Else
          'AnyForm was not passed from the calling function
    End If

  3. #3
    Join Date
    Oct 2009
    Posts
    7

    Re: VB6 Functions: Optional Parameters

    Thank you Shuja Ali !!

    Just what I needed.

    ABasicNut

Tags for this Thread

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

Featured