function returning array

  • Thread starter Thread starter dreamer
  • Start date Start date
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..
 
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
 

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

Back
Top