migrating vb6 optional parameters

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
guy said:
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?

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.
 
guy said:
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?

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
///
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top