Results 1 to 3 of 3

Thread: Oddity

  1. #1

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Oddity

    FWIW - I had a method that looked like this

    Code:
        Public Sub WontCollapse(Optional para As String = "")
    
        End Sub
    The important part is that it won't allow the method to collapse with one Optional argument.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,397

    Re: Oddity

    Confirmed on my end, that's not only odd it does that but also odd that I haven't noticed. Typically I won't setup optional parameters though, I tend to create multiple methods with different signatures. E.g. in your situation:
    Code:
    Public Sub Foo()
        Sub("")
    End Sub
    
    Public Sub Foo(para As String)
        ' do something
    End Sub
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Oddity

    Same here, for the last decade plus. At some point I read that optional parameters were discouraged, though I forget why. It shouldn't be performance, as the compiler could quietly turn an optional parameter into two different methods...and that may be what it does anyways.
    My usual boring signature: Nothing

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