</PRE><PRE><%
<B>'**** March 2001 ****
'Author: Anders Franzen
'anders.franzen@banqit.com
'
'A easy way to sort a one dimensional array
'I use it a lot
'********************
</B>
Option Explicit
Function SelectionSort(TempArray, SortOrder)
Dim MaxVal, MaxIndex, i, x
<B>' Step through the elements in the array starting with the last element.
</B>For i = UBound(TempArray) To 0 Step -1
<B> ' Set MaxVal to the element in the array and save the
' index of this element as MaxIndex.
</B> MaxVal = TempArray(i)
MaxIndex = i
<B> ' Check the selected sortorder of the array
' "<" for DESC and ">" for ASC
</B> If SortOrder = "<" Then
<B> ' Loop through the remaining elements to see if any is
' larger than MaxVal. If it is then set this element
' to be the new MaxVal.
</B> For x = 0 To i
If TempArray(x) < MaxVal Then
MaxVal = TempArray(x)
MaxIndex = x
End If
Next
Else
For x = 0 To i
If TempArray(x) > MaxVal Then
MaxVal = TempArray(x)
MaxIndex = x
End If
Next
End If
If MaxIndex < i Then
TempArray(MaxIndex) = TempArray(i)
TempArray(i) = MaxVal
End If
<B>'You can insert any one dimensional array here
</B>TheArray = SelectionSort(TheArray, ">") 'Use ">" for Ascending and "<" for Descending
For i = 0 To UBound(TheArray)
Response.Write(TheArray(i) & "<br>")
Next