您的位置:首页 > 编程语言 > ASP

[导入]ASP常用函数:SortArray2()

2008-01-24 11:31 435 查看
<%
'功能:对一个二维数组的指定列进行排序,DESC为倒序
'来源:http://jorkin.reallydo.com/article.asp?id=447
'需要Swap过程: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 iSortDirection = -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 iSortDirection = -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
%>

文章来源:http://Jorkin.Reallydo.Com/default.asp?id=447
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: