20 April 2022 05:00
[vba] -- return an ArrayList from a function
Hello Paul
Is there a way to return an ArrayList from a function, like a bellow?
This is the code I have implemented
Public Function ReturnArrayList() As ArrayList // or return type As Variant
Dim alist As ArrayList
Set alist = New ArrayList // Early Binding
alist.Add “a”
alist.Add “b”
alist.Add “c”
alist.Add “240”
ReturnArrayList = alist
End Sub
Sub GetArrayList()
Dim alist As ArrayList
alist = ReturnArrayList()
MsgBox alist(0)
End Sub
Thank you,
Nishan
Reply
Paul Kelly
Paul Kelly on December 24, 2019 at 7:56 am
Hi Nishan,
You need to use Set when returning an object.
1
(2 marks)