2012년 4월 5일 목요일

classic ASP 2demension array sort


classic asp 2demension array sort

asp 2차원 배열정렬

'==============================================
function arraySort( arToSort, sortBy, compareType, direction )
'==============================================
Dim c, d, e, smallestValue, smallestIndex, tempValue
For c = 0 To uBound( arToSort, 2 ) - 1
 smallestValue = arToSort( sortBy, c )
 smallestIndex = c
 For d = c + 1 To uBound( arToSort, 2 )
  if compareType = "Text" Then
   If direction = "desc" Then
    if strComp( CStr(arToSort( sortBy, d )), CStr(smallestValue) ) = -1 Then
     smallestValue = arToSort( sortBy, d )
     smallestIndex = d
    End if
   Else
    if strComp( CStr(arToSort( sortBy, d )), CStr(smallestValue) ) = 1 Then
     smallestValue = arToSort( sortBy, d )
     smallestIndex = d
    End if
  End If
  elseif compareType = "Date" then
   if not isDate( smallestValue ) then
    arraySort = arraySort( arToSort, sortBy, false)
   exit function
  else
   if dateDiff( "d", arToSort( sortBy, d ), smallestValue ) > 0 Then
    smallestValue = arToSort( sortBy, d )
    smallestIndex = d
   End if
  end if
  elseif compareType = "Number" Then
   if clng( arToSort( sortBy, d ) ) < clng(smallestValue) Then
    smallestValue = arToSort( sortBy, d )
    smallestIndex = d
   End if
  end if
 Next
 if smallestIndex <> c Then 'swap
  For e = 0 To uBound( arToSort, 1 )
   tempValue = arToSort( e, smallestIndex )
   arToSort( e, smallestIndex ) = arToSort( e, c )
   arToSort( e, c ) = tempValue
  Next
 End if
Next
arraySort = arToSort
end function

 productEvList = arraySort (productEvList, orderbyNum, "Text", "desc" )

댓글 없음:

댓글 쓰기