function returning array

D

dreamer

I've read that it possible for a function to return an array but I ca
get it working.
I've a function that extracts a string and puts characters in an array
It does so with every string so the size of the array is differen
every time. The idea is that the function returns an array to the sub
For example, the sub is running an index from 1 to 100 and the functio
returns an array with values 11, 14 and 25. If the index is same numbe
as one of the values form the array returned by the function the su
will do some actions..
 
R

Ron Rosenfeld

I've read that it possible for a function to return an array but I can
get it working.
I've a function that extracts a string and puts characters in an array.
It does so with every string so the size of the array is different
every time. The idea is that the function returns an array to the sub.
For example, the sub is running an index from 1 to 100 and the function
returns an array with values 11, 14 and 25. If the index is same number
as one of the values form the array returned by the function the sub
will do some actions...

It should work if you set the function equal to the array:

Function foo(str As String)
Dim i As Long
Dim foobar()

For i = 0 To Len(str)
ReDim Preserve foobar(i)
foobar(i) = Mid(str, i + 1, 1)
Next i
foo = foobar
End Function

foo will contain the array.

Instead of checking the index, you could also consider using Ubound(foo).


--ron
 
Top