How to return array of user defined types, and then pass as an argument in VBA

Viewed 6706

I have a User Defined Type, Decision:

Public Type Decision
    choice As String
    cost As Double
End Type

I am trying to use an array of my UDTs to store the results of a dynamic program (choice and cost for a stage/state).

Public Function DPSolve(arg1, arg2, ...) as Decision
        Dim Table() As Decision
        ReDim Table(arg1, arg2+ 1)

        'do stuff that fills each Table().choice and Table().cost

        'return Table()
        DPSolve = Table()
End Function

If I want to then pass the result of this function to a new function (to say, print the Table() in Excel, or do more work using the Table() result, how do I do this?

I am trying

Sub Main
    Dim x as variant

    x = DPSolve(arg1, arg2, ...)

    Function2(x)
End Main

but am getting the following error: Compile Error

I have tried making x an array, but I get a "cannot assign to array" error. I have also tried making x a Decision, but that did not work either. The code is in a module.

Thanks!

2 Answers
Related