What's the VB.Net way to do this?

  • Thread starter Thread starter Bryan Dickerson
  • Start date Start date
B

Bryan Dickerson

In VB6, I did this: Public Function CallSub(ParamArray VarArg())
How do I do a similar thing in VB.Net?
 
Bryan Dickerson said:
In VB6, I did this: Public Function CallSub(ParamArray VarArg())
How do I do a similar thing in VB.Net?

'ParamArray' is still supported.
 
Bryan Dickerson said:
In VB6, I did this: Public Function CallSub(ParamArray VarArg())
How do I do a similar thing in VB.Net?

fwiw, just ran this through that "wizard"

VB6
'=============
Private Sub MySub(ParamArray VarArg())
Dim i As Integer
For i = 0 To UBound(VarArg)
Debug.Print VarArg(i)
Next
End Sub
'=============

VS05
'=============
Private Sub MySub(ParamArray ByVal VarArg() As Object)
Dim i As Short
For i = 0 To UBound(VarArg)
Debug.Print(VarArg(i))
Next
End Sub

'=============

Now wondering if ParamArray's as useless as it was in VB6 <g> Every time I
considered using ParamArray, I changed my mind (in favor of a real array)
for one reason or another. Especially with VB6 (as opposed to VB5 that
didn't support passing/recv'ing arrays as well as 6)
 
In order to maintain type safety wouldn't you want to use the new function
overloading features of VB.NET instead of ParamArray?
 
TrtnJohn said:
In order to maintain type safety wouldn't you want to use the new function
overloading features of VB.NET instead of ParamArray?

'ParamArray' doesn't compromise type safety.
 
The type of each parameter is a variant. (VB 6.0). The compiler cannot
enforce type safety when working with variants.
 
TrtnJohn said:
The type of each parameter is a variant. (VB 6.0). The compiler cannot
enforce type safety when working with variants.

Yep, but this does not apply to VB.NET. In VB.NET, any type can be used
('ParamArray Foo() As Integer', for example).
 
Bryan Dickerson said:
In VB6, I did this:
Public Function CallSub(ParamArray VarArg())
How do I do a similar thing in VB.Net?

Public Function X( ByVal ParamArray Args as Object())
... or ..
Public Function X( ByVal ParamArray Args as String())
... or ..
Public Function X( ByVal ParamArray Args as SomeOtherType())

or, even, all three ... ;-)

HTH,
Phill W.
 

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