[Import] common ASP functions: SortArray2 ()

Source: Internet
Author: User

<%
'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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.