Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing an array argument

Status
Not open for further replies.

NicolaasH

Technical User
Sep 11, 2007
38
I was wondering how I can efficiently pass an array from one procedure to the other. VBA accepts the following:
Code:
Public Sub Checksheet()
Dim OmmissionArray(1 To 14, 1 To 8) As Integer

'......some stuff to fill the array
CompleteOmmissions OmmissionsArray:=OmmissionsArray

End Sub

Public Sub CompleteOmmissions(OmmissionsArray)
    
'.....rest of programming

End Sub

It seems like I cannot declare the dimensions of the array in the sub statement. I was wondering what the dimensions of the array are in CompleteOmmissions. Is it still a bounded array of 8 by 14 integers, or is it an unbounded variant array (memory inefficient)

Thanks!
Nick
 
Hi,


Code:
Public Sub CompleteOmmissions(paramarray OmmissionsArray as Variant)
    
'.....rest of programming

End Sub

Cheers,

Roel

 
Hi,

Is this not exactly the thing I do not want to happen?

I want to keep it a bounded integer array (in this case 8 * 14 = 112*2 bytes=224 bytes), and not stretch it to a variant array (112*16 bytes=1792 bytes).
 
... or:
Code:
Public Sub Checksheet()
Dim OmmissionArray(1 To 14, 1 To 8) As Integer
'......some stuff to fill the array

CompleteOmmissions OmmissionArray

End Sub

Public Sub CompleteOmmissions(OmmissionsArray() As Integer)
'.....rest of programming

End Sub
This solution requires non-variant array. You can use Ubound and Lbound functions to find array's size.

combo
 
sorry, didn't read the last part of your post.

AFAIK it's not possible to have anything but a variant as paramarray.

If you want to maintain the bound array you can declare it as a global variable, but I wouldn't go with that unless absolutely necessary.

Another option could be to write the variant-array back to a bound array declared in the receiving procedure.

Maybe one of the specialists here can provide more info on this.

Cheers,
Roel
 
Thanks guys. I added the parentheses that combo suggested and that works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top