PDA

View Full Version : Returning Arrays From Functions



ChloeRadshaw
06-02-2009, 10:50 AM
I come from a Java background - Can anyone explain why this is disallowed?

And how best to achieve this?



Public Function testMe() As Variant()
ReDim abc(0 To 1, 0 To 1) As Long

testMe = abc
End Function

mdmackillop
06-02-2009, 11:14 AM
Sub test()
Dim t, msg
For Each t In testMe
msg = msg & t
Next
MsgBox msg
End Sub

Public Function testMe() As Variant
ReDim abc(0 To 1, 0 To 1) As Long
abc(0, 0) = 1
abc(1, 0) = 2
abc(0, 1) = 3
abc(1, 1) = 4
testMe = abc
End Function

ChloeRadshaw
06-02-2009, 01:37 PM
Thanks - But why does this work conceptually?

How can you declare a function that returns a variant() - Notice the array on the signature.

Thats my question

mdmackillop
06-02-2009, 02:13 PM
Sorry, I'm not much on theory. I'm sure someone else will come along though.

ChloeRadshaw
06-03-2009, 01:19 AM
Anyone please? I am keen to know the answer here...

Thanks