I’m testing a very basic agent to sort element and I having always the same error type mismatch when calling the function to sort
here is my code :
Dim testTab() As String
Redim Preserve testTab(3) As String
testTab(0) = "Marc"
testTab(1) = "Anthony"
testTab(3) = "Gilles"
SortArray2 testTab <== type mismatch
thanks for your help
for information
where SortArry2 is the code from notes.net below :
Function SortArray2 (Array$())
’ this code taken from Notes.net, and slightly modified to sort by numeric value
Dim MaxElement%, MidPoint%, I%, J%, Done%
MaxElement% = Ubound(Array$)
Select Case MaxElement%
Case 0
Exit Function
Case 1
If Cint (Array$(0)) > Cint (Array$(1)) Then
Swap Array$(0), Array$(1)
End If
Case Else
MidPoint% = MaxElement%
While MidPoint% > 0
MidPoint% = MidPoint% \ 2
Do
Done% = True
For J% = 0 To MaxElement% - MidPoint%
I% = J% + MidPoint%
If Cint (Array$(J%)) > Cint (Array$(I%)) Then
Swap Array$(J%), Array$(I%)
Done% = False
End If
Next
Loop Until Done%
Wend
End Select
End Function
Function Swap (A$, B$)
’ goes w/ SortArray which was taken from notes.net
Nicholas, looks like the reason that this is failing is that the sort routine, as modified, is trying to sort as numeric. (Note the CInt around the array elements.) Remove all CInt references and retry it. If that doesn’t work, reply back here.
I originally posted this sort routine back in 2004. If you want the original, search the forum for MaxElement% and you can get the original unmodified code that was for a string array. If it is needed for sorting a numeric array, it should be properly modified to do that.