Results 1 to 3 of 3

Thread: functions

  1. #1

    Thread Starter
    Addicted Member Rudy's Avatar
    Join Date
    Sep 2000
    Location
    BC, Canada
    Posts
    198

    functions

    is there a way to have a default value for a function so that if no values are passed, the function uses the default one

    heres what im talking about in c++
    nameoffunction (int x, int y = 0)

    so if u call the function with only one parameter, the function will use 0 for y

    i want the same thing but for VB
    *Rudy^
    Visual Studio 6 Ent. SP5
    Windows 2000 SP4
    Windows XP SP1a

  2. #2
    Hyperactive Member dogfish227's Avatar
    Join Date
    Oct 2002
    Location
    GA
    Posts
    409
    yes just do something like:

    VB Code:
    1. Private Function func(Optional num As Integer = 1)
    2.  
    3. End Function

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    The optional parameter must come after normal parameters.
    So to pass two integers, the second of which being optional, you would :

    VB Code:
    1. Function nameOfFunction(ByVal x As Long, Optional y As Long = 0)
    2.  
    3. End Function
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

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