Excel vba - passing a 3-dimensional array to a subroutine

J

joran6

Hello,

I'm having trouble getting the syntax right for passing a 3-dimensional
array to a subroutine.
The array in question in originally defined as
dim variable() as single

Later...

ReDim variable(x,y,z) (through a series of For statements)

and later still....

Subroutine is called (subroutine needs a specific component of array)
A function would work for me as well.

Hope someone can help...

joran6
 
Z

Zack Barresse

Hi joran6,

Try dimming the variable as "Dim Variable" instead and leave it as a Variant
type.
 
Z

Zack Barresse

Did you try the Variant like I showed? You could also try posting all of
your code.
 
G

Guest

Sub Main()
Dim variable() As Single

x = 10
y = 3
z = 3
ReDim variable(1 To x, 1 To y, 1 To z)
For i = 1 To x
For j = 1 To y
For k = 1 To z
variable(i, j, k) = i * j * k * Rnd()
Next k, j, i
Dummy variable
End Sub

Sub Dummy(v() As Single)
MsgBox v(UBound(v, 1), UBound(v, 2), _
UBound(v, 3))
End Sub


works fine for me as an illustration. What do you mean by needs a component?
 

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