ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   function returning array (https://www.excelbanter.com/excel-programming/300709-function-returning-array.html)

dreamer[_18_]

function returning array
 
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..

--
Message posted from http://www.ExcelForum.com


Ron Rosenfeld

function returning array
 
On Tue, 8 Jun 2004 02:40:33 -0500, dreamer
wrote:

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...


---
Message posted from http://www.ExcelForum.com/


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


All times are GMT +1. The time now is 11:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com