Passing Multi-dimensional arrays in VBA

sharpnova

Registered User.
Local time
Yesterday, 16:17
Joined
Jun 9, 2011
Messages
69
I have a two dimensional array of strings:

Dim testArray(3, 3) as string

I need to pass this to a function.

I've tried every combination of syntax possible for passing this to a function to no avail.

Function analyzeCell(ByRef currentArray(,) as String) gives "Expected:)"

Function analyzeCell(ByRef currentArray as String(,) gives "Expected: list separator or )"
 
This works for me:

Code:
function analyzeCell(strArray() As String)

Here's the code I used to test it:


Code:
Sub startHere()
    Dim strNamesArray(3, 3) As String
    Dim strTemp As String
    
    strNamesArray(2, 2) = "Fred"
    strTemp = fetchArrayItem(strNamesArray, 2, 2)
    MsgBox strTemp

End Sub

Function fetchArrayItem(strArray() As String, a As Integer, b As Integer) As String
    fetchArrayItem = strArray(a, b)
End Function
 
Thanks for your help. So in VBA, no matter what the dimensions of the array, is this how it gets parameterized?
 

Users who are viewing this thread

Back
Top Bottom