Hi there,
I am trying to sort an array of strings. When i run the code, I get a compile error saying that the array argument must be passed ByRef. I have my sorting function and calling line below. If anyone can figure out why I am getting this message, also if you see anything wrong in my sort function, I would really appreciate it, because I can't figure it out for the life of me.
(options() is the array that I am trying to sort)
Private Sub ModelCombo_Change()
...
...
Sort(options) --THIS IS WHERE THE ERROR REFERENCES
...
end sub
Function Sort(ByRef Data() As String) As String
Dim Temp As String, i As Integer, j As Integer
For i = 1 To UBound(Data)
If StrComp(Data(i - 1), Data(i), 1) = 1 Then
j = i
While j > 0
If StrComp(Data(j - 1), Data(j), 1) = 1 Then
Temp = Data(j)
Data(j) = Data(j - 1)
Data(j - 1) = Temp
Else
j = 0
End If
j = j - 1
Wend
End If
Next i
Sort = Data
End Function
Thanks,
Jeff
I am trying to sort an array of strings. When i run the code, I get a compile error saying that the array argument must be passed ByRef. I have my sorting function and calling line below. If anyone can figure out why I am getting this message, also if you see anything wrong in my sort function, I would really appreciate it, because I can't figure it out for the life of me.
(options() is the array that I am trying to sort)
Private Sub ModelCombo_Change()
...
...
Sort(options) --THIS IS WHERE THE ERROR REFERENCES
...
end sub
Function Sort(ByRef Data() As String) As String
Dim Temp As String, i As Integer, j As Integer
For i = 1 To UBound(Data)
If StrComp(Data(i - 1), Data(i), 1) = 1 Then
j = i
While j > 0
If StrComp(Data(j - 1), Data(j), 1) = 1 Then
Temp = Data(j)
Data(j) = Data(j - 1)
Data(j - 1) = Temp
Else
j = 0
End If
j = j - 1
Wend
End If
Next i
Sort = Data
End Function
Thanks,
Jeff