Search notes:

VBA: returning values from functions

Returning an array from a function

This is how I believe how an array should be returned from a function.
One is wondering if this is really the most elegant approach.
option explicit

function getArray() as string()

    dim ret(3) as string

    ret(1) = "one"
    ret(2) = "two"
    ret(3) = "three"
    
    getArray = ret

end function

sub main()

    dim ary() as string
    
    ary = getArray()
    
    for i = 1 to uBound(ary)
        msgBox(ary(i))
    next i

end sub
Github repository about-VBA, path: /language/subs-and-functions/returning-values/array.bas
See also this link.

See also

VBA: User defined subs and functions

Index