<%
'Function: sorts specified columns of a two-dimensional array, and DESC is in reverse order.
'Source: http://jorkin.reallydo.com/article.asp? Id = 447
'The Swap process is required: http://jorkin.reallydo.com/article.asp? Id = 446
Function SortArray2 (ByVal aSortArray (), ByVal iSortColumn, ByVal sSortDirection)
On Error Resume Next
Dim I, j, k
Dim sValue, JValue
Dim iLBound, iUBound
Dim tmp
Dim iVarType, iSortDirection, iCheckIndex
ILBound = LBound (aSortArray, 2)
IUBound = UBound (aSortArray, 2)
Select Case UCase (sSortDirection)
Case "DESC", "D"
Isortdirection = 1
Case else
Isortdirection =-1
End select
Isortcolumn = bint (isortcolumn)
If isortcolumn <0 or isortcolumn> ubound (asortarray, 1) then
Sortarray2 = asortarray
Exit Function
End if
Icheckindex = ilbound
While Len (TRIM (asortarray (isortcolumn, icheckindex) = 0 and icheckindex <ubound (asortarray, 2)
ICheckIndex = iCheckIndex + 1
Wend
If IsDate (Trim (aSortArray (iSortColumn, iCheckIndex) Then
IVarType = 7
Else
If IsNumeric (Trim (aSortArray (iSortColumn, iCheckIndex) Then
IVarType = 5
Else
IVarType = 8
End If
End If
For I = iLBound To iUBound-1
SValue = aSortArray (iSortColumn, I)
JValue = I
For j = I + 1 To iUBound
Select Case iVarType
Case 8
If StrComp (aSortArray (iSortColumn, j), sValue, 1) = iSortDirection Then
SValue = aSortArray (iSortColumn, j)
JValue = j
End If
Case 7
If isortction ction =-1 Then
If DateDiff ("s", aSortArray (iSortColumn, j), sValue)> 0 Then
Svalue = asortarray (isortcolumn, J)
Jvalue = J
End if
Else
If datediff ("S", asortarray (isortcolumn, J), svalue) <0 then
SValue = aSortArray (iSortColumn, j)
JValue = j
End If
End If
Case 5
If isortction ction =-1 Then
If CDbl (aSortArray (iSortColumn, j) <CDbl (sValue) Then
SValue = aSortArray (iSortColumn, j)
JValue = j
End If
Else
If CDbl (aSortArray (iSortColumn, j)> CDbl (sValue) Then
SValue = aSortArray (iSortColumn, j)
JValue = j
End If
End If
End Select
Next
If JValue <> I Then
For k = 0 To UBound (aSortArray, 1)
Swap aSortArray (k, JValue), aSortArray (k, I)
Next
End If
Next
SortArray2 = aSortArray
End Function
%>
Source: http://Jorkin.Reallydo.Com/default.asp? Id = 447