Passing array as parameter

J

John

Hi

Is it possible to pass array of strings as parameter and if so how can I
figure in the called SUB the number of elements in the passed array?

Thanks

Regards
 
D

Dirk Goldgar

John said:
Hi

Is it possible to pass array of strings as parameter and if so how can I
figure in the called SUB the number of elements in the passed array?


Sure you can pass an array as a parameter. For example:

'----- start of code -----
Sub ProcessArray(MyArray() As String)

' This procedure accepts an array of strings as an argument.

Dim I As Long

Debug.Print "MyArray has " & UBound(MyArray) - LBound(MyArray) + 1 & "
elements."

For I = LBound(MyArray) To UBound(MyArray)
Debug.Print MyArray(I)
Next I

End Sub

Sub ProcessArrayDemo()

' This procedure will call ProcessArray.

Dim strArray() As String

strArray = Split("A,B,C", ",")

ProcessArray strArray

End Sub
'----- end of code -----

Note that the above code allows only for a one-dimensional array. Also, it
may sometimes be useful to allow the procedure to accept a Variant
containing an array, rather than an array itself. That may give a little
more flexibility.
 
V

valdir junior

John said:
Hi

Is it possible to pass array of strings as parameter and if so how can I
figure in the called SUB the number of elements in the passed array?

Thanks

Regards
 

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