i ended up making this function:
Code:
Function SortArray(aUnsorted, iAsc)
'variables
Dim itemp, i, j
'bubble sort (dubble for loop)
For i = 0 To Ubound(aUnsorted) -1
For j = i to Ubound(aUnsorted)
If iAsc = 1 Then 'ascending
'exchange items
If aUnsorted(j) < aUnsorted(i) Then
itemp = aUnsorted(i)
aUnsorted(i) = aUnsorted(j)
aUnsorted(j) = itemp
End if
Else 'descending
'exchange items
If aUnsorted(j) > aUnsorted(i) Then
itemp = aUnsorted(i)
aUnsorted(i) = aUnsorted(j)
aUnsorted(j) = itemp
End if
end if
Next
next
'return value is the sorted array
SortArray = aUnsorted
End Function
Process steps:
1. you generate an array with the values to be sorted
2. you call this function
Code:
aSortedArray = SortArray(aUnsortedArray, 1) 'if ascending
aSortedArray = SortArray(aUnsortedArray, 2) 'if descending
3. You work with the aSortedArray
Bookmarks