Results 1 to 6 of 6

Thread: [RESOLVED] When declairing an optional argument

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    294

    Resolved [RESOLVED] When declairing an optional argument

    Is there a way to tell if the arguemnt was passed or not?
    VB Code:
    1. Sub LoadConfiguration(ByVal ConfigurationFile As String, _
    2.  ByRef ConfigurationCollection As Collection, _
    3.  Optional ByRef KeyCollection As Collection)
    4.  If KeyCollection Then: MsgBox "twas passed" '?
    5. End Sub

  2. #2
    Hyperactive Member vbcode1980's Avatar
    Join Date
    Nov 2005
    Location
    Anywhere the wind blows
    Posts
    365

    Re: When declairing an optional argument

    Can't you check if KeyCollection <> empty?

    (Don't have VB 6 here so can't test if that works.. )
    I code C#....

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: When declairing an optional argument

    Quote Originally Posted by vbcode1980
    Can't you check if KeyCollection <> empty?

    (Don't have VB 6 here so can't test if that works.. )
    Exactly right.

    Just do a quick If to see if that value has anything in it.

  4. #4
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043

    Re: When declairing an optional argument

    VB Code:
    1. Sub LoadConfiguration(ByVal ConfigurationFile As String, _
    2.  ByRef ConfigurationCollection As Collection, _
    3.  Optional ByRef KeyCollection As Collection = Nothing)
    4.  
    5.     If KeyCollection Is Nothing Then
    6.        MsgBox "not passed"
    7.     Else
    8.        MsgBox "twas passed"
    9.     End If
    10.  
    11. End Sub
    oh1mie/Vic


  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    294

    Re: When declairing an optional argument

    You must spread some Reputation around before giving it to Hack again.

    Thanks guys.

  6. #6
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: When declairing an optional argument

    Empty works only for Variants.
    You have to check for Nothing.

    VB Code:
    1. If Not KeyCollection Is Nothing Then: MsgBox "It was passed"

    EDIT: oh1mie, you have beaten me
    Frans

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