0

I'm trying to find a way to pass a multi-dimensional array to my Function in VBA. I tried google but didn't find anything to help me on my way.

This is what I tried:

Public Function getData(Query()() As String) As Integer

But that only resulted in a direct error from the enviroment saying it expects a delimiter or ')'.

2
  • :) Show me how you declared your Query()() array please Commented Dec 12, 2013 at 14:35
  • My question is how can I pass a multi-dimensional Array to a function in VBA. So I would need to know how to do that to. Thanks for trying to help @mehow Commented Dec 12, 2013 at 14:40

1 Answer 1

1

You can't.

Query()() as String is not a valid expression in VBA.


This is how you would create a 2D array in VBA and how to write a function that accept it

Sub Main()

    Dim arr(0 To 1, 0 To 1) As String
    arr(0, 0) = "element 0,0"
    arr(1, 0) = "element 1,0"
    arr(0, 1) = "element 0,1"
    arr(1, 1) = "element 1,1"

    Call GetData(arr)

End Sub


Function GetData(myArray() As String) As Integer

End Function

and a 3D+ version

Sub Main()

    Dim arr(0 To 1, 0 To 1, 0 To 1) As String
    arr(0, 0, 0) = "element 0,0,0"
    arr(1, 0, 0) = "element 1,0,0"
    arr(0, 1, 0) = "element 0,1,0"
    arr(0, 1, 1) = "element 0,1,1"
    arr(0, 0, 1) = "element 0,0,1"
    arr(1, 0, 0) = "element 1,0,0"
    arr(1, 1, 0) = "element 1,1,0"
    arr(1, 0, 1) = "element 1,0,1"
    arr(1, 1, 1) = "element 1,1,1"

    Call GetData(arr)

End Sub


Function GetData(myArray() As String) As Integer

End Function
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.