hexagon logo

Return array from function.

In Basic Script I would like to return an array from a function and cannot figure what I'm doing wrong. I get and unspecified error.

Code sample:

Sub ApplyShift()
Dim TmpVal
TmpVal=DOFTransForm(0,0,0,1,1)
End Sub ' ApplyShift()

Function DOFTransForm(xval As Single, yval As Single, zval As Single, txval As Single, tyval As Single) As Single
Dim ResultArray(2) As Single

ResultArray(0)=txval
ResultArray(1)=tyval

DOFTransForm = ResultArray

End Function ' DOFTransForm

Sub Main()

ApplyShift

End Sub
Parents
  • Dim TmpVal() maybe?


    If that doesn't work then you could try something like this...


    Sub ApplyShift()
    Dim TmpVal()
    Redim TmpVal(1)

    DOFTransForm(0,0,0,1,1, TmpVal)

    End Sub ' ApplyShift()



    Sub DOFTransForm(xval As Single, yval As Single, zval As Single, txval As Single, tyval As Single, ByRef ResultsArray() as single)


    ResultArray(0)=txval
    ResultArray(1)=tyval



    End Sub' DOFTransForm




    Sub Main()

    ApplyShift

    End Sub




    Change from function to a sub, and create the array in the calling procedure and pass it ByRef into the sub.
Reply
  • Dim TmpVal() maybe?


    If that doesn't work then you could try something like this...


    Sub ApplyShift()
    Dim TmpVal()
    Redim TmpVal(1)

    DOFTransForm(0,0,0,1,1, TmpVal)

    End Sub ' ApplyShift()



    Sub DOFTransForm(xval As Single, yval As Single, zval As Single, txval As Single, tyval As Single, ByRef ResultsArray() as single)


    ResultArray(0)=txval
    ResultArray(1)=tyval



    End Sub' DOFTransForm




    Sub Main()

    ApplyShift

    End Sub




    Change from function to a sub, and create the array in the calling procedure and pass it ByRef into the sub.
Children
No Data