I am would like to write a user defined function (UDF), A that returns multiple values (let's say 3). I would then like to use these values in another UDF, B.
I have been following
https://www.geeksengine.com/article/vba-function-multiple-values2.html
on what VBA data structures would support this. I was originally using a collection to store the multiple values from UDF A, but in my use case, index 0, 1 and 2 have some value, so would like to use an array instead of a collection so that I can index with base 0 (I am not sure if this is possible with collections - it seems the first element is .Item(1)).
The problem is, I cannot seem to retrieve the values of the array returned by UDF A inside UDF B.
A minimum (not) working example:
Function A() As Variant
Dim arr(3) As Variant
arr(0) = "zero"
arr(1) = "one"
arr(2) = "two"
A = arr
MsgBox "Function A"
MsgBox arr(0)
End Function
Function B() As Variant
Dim arry(3) As Variant
Set arry = A()
MsgBox "Function B"
MsgBox arry(0)
End Function
Sub debugfunc()
MsgBox B()
End Sub
I have tried both Set arry = A() and arry = A(). Both produce 'Ca't assign to array' errors when running the debugfunc sub.
Any ideas?
Dim arry(3). You cannot assign to an arrayDimed with dimensions. Dim without dimensions.