none
HoTo: pass user defined type array to function/procedure RRS feed

  • Question

  • Hello.

    I want to pass user defined type (UDT) wich is array to function or procedure.

    How can i make this?

    UDT array looks like this:

    Private Type ABFactor
        a As Single
        b As Single
    End Type
    
    Private Sub Form_Load()
    
    Dim ABFactorArr(8) As ABFactor
    Dim i As Byte
    For i = 0 To UBound(ABFactorArr)
        ABFactorArr(i).a = i
        ABFactorArr(i).b = i + 10
    Next i
    'quick test
    Debug.Print ABFactorArr(6).b
    
    End Sub



    Tuesday, November 20, 2012 4:01 PM

Answers

  • If you want to pass your UDT to another procedure in your form (or same class module), pass it as you would any other variable, eg

    ' in Private Sub Form_Load()
    test ABFactorArr
    
    Private Sub test(myUDTarray() As ABFactor)
         Debug.Print myUDTarray(6).b
    End Sub

    However if you want to pass to a procedure in another module you will need to declare the UDT as Public in a normal module

    Peter Thornton

    Tuesday, November 20, 2012 5:16 PM
    Moderator