migrating vb6 optional parameters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • guy

    migrating vb6 optional parameters

    found this oddity-
    copying a vb6 function with optional parameters and pasting it into a vb2003
    class, for conversion purposes, it all works fine except that the collapsing
    "-" on the LHS goes away, only to return if "Optional" is removed. Strange.
    anyone else had this?

    guy

  • Larry Lard

    #2
    Re: migrating vb6 optional parameters


    guy wrote:[color=blue]
    > found this oddity-
    > copying a vb6 function with optional parameters and pasting it into a vb2003
    > class, for conversion purposes, it all works fine except that the collapsing
    > "-" on the LHS goes away, only to return if "Optional" is removed. Strange.
    > anyone else had this?[/color]

    One thought: In VB6, you could just say "Optional param As type" and be
    done with it, but in VB.NET "Optional parameters must specify a default
    value" so if you just copy this valid in VB6) syntax into VB.NET:

    Public Sub T(ByVal a As Integer, Optional ByVal g As Integer)

    End Sub

    you will get a squiggly line under the ), and no - collapsing section,
    because it doesn't compile. Change it to eg

    Public Sub T(ByVal a As Integer, Optional ByVal g As Integer = 0)

    End Sub

    and you get your - collapsing section.

    --
    Larry Lard
    Replies to group please

    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: migrating vb6 optional parameters

      "guy" <guy@discussion s.microsoft.com > schrieb:[color=blue]
      > copying a vb6 function with optional parameters and pasting it into a
      > vb2003
      > class, for conversion purposes, it all works fine except that the
      > collapsing
      > "-" on the LHS goes away, only to return if "Optional" is removed.
      > Strange.
      > anyone else had this?[/color]

      The "+" isn't shown as long as there is a compile-time error in your method
      declaration. I assume you forgot to assign a value to the optional
      parameter, which will fix the problem:

      \\\
      Public Sub Foo(Optional ByVal Number As Integer = 0)
      ...
      End Sub
      ///

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      • guy

        #4
        Re: migrating vb6 optional parameters

        Larry,Herfried, yes I thought that was the problem too but even with the
        default in place no "-", however after removing the optional parameter
        clicking on a different line and then replacing it it worked correctly.

        guy

        "Herfried K. Wagner [MVP]" wrote:
        [color=blue]
        > "guy" <guy@discussion s.microsoft.com > schrieb:[color=green]
        > > copying a vb6 function with optional parameters and pasting it into a
        > > vb2003
        > > class, for conversion purposes, it all works fine except that the
        > > collapsing
        > > "-" on the LHS goes away, only to return if "Optional" is removed.
        > > Strange.
        > > anyone else had this?[/color]
        >
        > The "+" isn't shown as long as there is a compile-time error in your method
        > declaration. I assume you forgot to assign a value to the optional
        > parameter, which will fix the problem:
        >
        > \\\
        > Public Sub Foo(Optional ByVal Number As Integer = 0)
        > ...
        > End Sub
        > ///
        >
        > --
        > M S Herfried K. Wagner
        > M V P <URL:http://dotnet.mvps.org/>
        > V B <URL:http://classicvb.org/petition/>
        >
        >[/color]

        Comment

        Working...