-
Hello,
I got a slight problem...
I would like to pass a two-dimensional array from a sub to another sub.
Something like this:
Dim matrix(1 to 10, 1 to 10)
Sub CommandButton1_click()
...
Call solve(matrix())
...
End sub
Sub solve(Paramarray matrix() as Variant)
...
...
End sub
It doesn't work...?????
Does anyone have a solution?
Kind regards,
Gertjan
-
Param array is expection the list of parameters, so the correct way to get it is like this:
Code:
Private Function MyFunction(ParamArray arrValues()) As Boolean
'Do something here
End Function
The way you would have to pass it is like this:
Call MyFunction("a","b","c")
Assuming that I'm passing 3 string values.
In your situation you could use array as a parameter:
Code:
Private Function MyFunction(arrValues() As Variant) As Bollean
'Do something here
End Function
Then you can pass the array like you had:
Code:
Dim arrMyArray(10)
Call MyFunction(arrMyArray)
Regards,
-
ParamArray is used to pass a variable number of values. Do this instead
Code:
Option Explicit
Sub CommandButton1_click()
Dim matrix(1 To 10, 1 To 10) As Integer
matrix(1, 1) = 32
matrix(4, 3) = 99
Call solve(matrix())
'...
End Sub
Sub solve(matrix() As Integer)
Dim x
Dim y
For x = 1 To 10
For y = 1 To 10
If matrix(x, y) <> 0 Then
Debug.Print matrix(x, y)
End If
Next y
Next x
End Sub
-
I know there are many ways, but what about storing arrays in a variant:
Function blabla()
dim array(x,y)
blabla=array
end function