CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2000
    Location
    Mesa, AZ
    Posts
    189

    Optional Keyword



    Can someone tell me what the default is for a variable that is declared as optional? For example:


    Function Fun1(optional byval an_int as Integer)
    Fun2(an_int)
    End Function


    Function Fun2(byval an_int as Integer)
    ' do something here with an_int
    End Function





    What will this pseudocode do?


    I will rate all useful suggestions

    In reply to:

    A man who asks a question is a fool for 15 minutes. A man who doesn't ask a question is a fool for a lifetime. -Chinese Proverb




    Karok

  2. #2
    Join Date
    Jun 2001
    Posts
    44

    Re: Optional Keyword

    When you declare a optional parameter. You must set default value such as
    Function Fun1(optional byval an_int as Integer=12)
    If you don't
    parameter value be zero.







  3. #3
    Join Date
    Sep 2001
    Posts
    16

    Re: Optional Keyword

    Hi,
    The syntax for typed optional arguments allows you to specify a default value. If the argument is omitted when the procedure is called, then the argument will have the default value. Here u didnt specify the default value. The default value for the integer when declared will be 0. So it will take it as 0.
    If u are declaring the variable as variant then u can use the IsMissing() function to find out whether the procedure is called with the argument or not.
    Have a nice day.
    sunil.


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