Passing an array to function

grahamw

Registered User.
Local time
Yesterday, 21:46
Joined
Aug 19, 2005
Messages
23
Hi all.
Really basic stuff I guess (for many) but my book only dedicates an inadequate 1/2 page to this.
I have an array of type 'single', Horse_ratings( contains a series of numbers)
Im getting confused by the ByVal option.
Whilst I try to solve this I'd be grateful for any suggestions on the coding for passing the array and the first line of the function.
Many Thanks,
Graham Wake
 
An easy way to deal with this is to pass an array to a function that accepts a variant. A simple example...

Code:
Private Sub Command0_Click()

'Create and fill an array.
    Dim MyArray(3) As Single
    MyArray(0) = 0
    MyArray(1) = 1
    MyArray(2) = 2
    MyArray(3) = 3
'Pass it to a function and get the return data.
    Dim MyNewArray() As Single
    MyNewArray = GetArray(MyArray)
'Test.
    Dim i As Integer
    For i = LBound(MyNewArray) To UBound(MyNewArray)
        Debug.Print MyNewArray(i)
    Next i

End Sub

Function GetArray(MyArray As Variant) As Variant

'Change the first value in the array.
    MyArray(0) = 200
'Pass back the array to the calling procedure.
    GetArray = MyArray

End Function

Regards,
Tim
 
Thanks Tim.
 

Users who are viewing this thread

Back
Top Bottom