I have always thought that the "Call" reserved word is optional when it comes to calling functions and subroutines.
However, I was attempting to implement my insertion sort function and, somehow, when i tried to pass the array into the function, not using the "Call" reserved word threw an error (if parameter is defined as an array - e.g. ByRef vData() as Double) or failed to update the array (if parameter is defined as variant - e.g. ByRef vData as Variant).
Any idea/explanation for such behaviour? Thank you!
However, I was attempting to implement my insertion sort function and, somehow, when i tried to pass the array into the function, not using the "Call" reserved word threw an error (if parameter is defined as an array - e.g. ByRef vData() as Double) or failed to update the array (if parameter is defined as variant - e.g. ByRef vData as Variant).
Any idea/explanation for such behaviour? Thank you!
Code:
Public Function fnc_SortInsertion(ByRef vData As Variant) As Boolean
Dim i As Long
Dim x As Long
Dim vTemp As Variant
fnc_SortInsertion = False
For i = LBound(vData, 1) + 1 To UBound(vData, 1)
vTemp = vData(i)
x = i - 1
While x > -1 And vData(x) > vTemp
vData(x + 1) = vData(x)
x = x - 1
Wend
vData(x + 1) = vTemp
Next i
If Err = 0 Then fnc_SortInsertion = True
End Function
Public Sub sub_testtest()
Dim vArray(1 To 3) As Double
vArray(1) = 3
vArray(2) = 10
vArray(3) = 5
Call fnc_SortInsertion(vArray)
Debug.Print vArray(3)
End Sub