Results 1 to 3 of 3

Thread: Question about Optional Parameters and Variant

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    29

    Question about Optional Parameters and Variant

    I am somewhat new to VBA, and I could swear I read something where it said that if I wanted to use the isMissing function against a certain parameter, that parameter had to be declared as variant in the function statement.

    Is that true? I thought I read that somewhere, but now I can't find somethign to verify it. Although, by change one of my optional parameters from Range to Variant did solve the error message, so I am leaning towards yes.

    If that is the case doesn't that mean you will have to declare all optional parameters variant, since you have to test to see if your parameter was included or not in the function?

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Question about Optional Parameters and Variant

    No.... because you can set a default value for optional parameters. That's what I do, I never declare parameters as variant, even optional ones. I set them to a default value, then test for that value to see if the parameter was actualy passed.

    Optional byref MyNewRange As Range = Nothing

    Then if you check to see if MyNewRange Is Nothing, then it wasn't passed. If it isn't nothing, then it was passed in.

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    29

    Re: Question about Optional Parameters and Variant

    ok, I see, I didn't know you could set the default optional parameter value within the parameter list like that. Thanks, I think I'll do that.

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