Sort an array of Numeric values, simple straightforward
Edit v3 2021-09-21: Adding ability to sort Asc or Desc
Originally from http://www.mykeblack.com/scripts/asp/arrays/sort-array-quick-method
Function sortArray(arrShort, Optional sortorder = 1)
' sortOrder = 1 > > > > Asc
' sortOrder = any > > Desc
For i = UBound(arrShort) - 1 To 1 Step -1
For j = 1 To i
If sortorder = 1 Then
If arrShort(j) > arrShort(j + 1) Then
temp = arrShort(j + 1)
arrShort(j + 1) = arrShort(j)
arrShort(j) = temp
End If
Else
If arrShort(j) < arrShort(j + 1) Then
temp = arrShort(j + 1)
arrShort(j + 1) = arrShort(j)
arrShort(j) = temp
End If
End If
Next
Next
sortArray = arrShort
End Function
' sortOrder = 1 > > > > Asc
' sortOrder = any > > Desc
For i = UBound(arrShort) - 1 To 1 Step -1
For j = 1 To i
If sortorder = 1 Then
If arrShort(j) > arrShort(j + 1) Then
temp = arrShort(j + 1)
arrShort(j + 1) = arrShort(j)
arrShort(j) = temp
End If
Else
If arrShort(j) < arrShort(j + 1) Then
temp = arrShort(j + 1)
arrShort(j + 1) = arrShort(j)
arrShort(j) = temp
End If
End If
Next
Next
sortArray = arrShort
End Function
arrShort
Views 4,934
Downloads 1,343
CodeID
DB ID
ANmarAmdeen
602
Revisions
v4.0
Tuesday
September
21
2021