pass array as a function parameter

D

DIOS

In VB2005 I have a function that takes an array of integers

Private Sub MyGroups(ByVal grpVals() As Integer)
'blah
End Sub

I can call the function no problem with two variables

Dim myvals() As Integer = {var1, var2}
MyGroups(myvals)

Is there a way to do this in one line like so
MyGroups( {var1, var2})

Ive tried various ways and searched for different approaches but cant
seem to find one that does it in one line.

AGP
 
A

Armin Zingler

Am 03.06.2010 18:16, schrieb DIOS:
In VB2005 I have a function that takes an array of integers

Private Sub MyGroups(ByVal grpVals() As Integer)
'blah
End Sub

I can call the function no problem with two variables

Dim myvals() As Integer = {var1, var2}
MyGroups(myvals)

Is there a way to do this in one line like so
MyGroups( {var1, var2})

Ive tried various ways and searched for different approaches but cant
seem to find one that does it in one line.


MyGroups(New Integer() {var1, var2})


Alternatively, if possible, you can declare a ParamArray:

Private Sub MyGroups(ByVal ParamArray grpVals() As Integer)

Call:

MyGroups(var1, var2)
MyGroups(myvals)
 
D

DIOS

Am 03.06.2010 18:16, schrieb DIOS:









  MyGroups(New Integer() {var1, var2})

Alternatively, if possible, you can declare a ParamArray:

   Private Sub MyGroups(ByVal ParamArray grpVals() As Integer)

Call:

  MyGroups(var1, var2)
  MyGroups(myvals)

Ahhh that works, thanks for the tip.

AGP
 

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

Top