View Single Post
  #1 (permalink)  
Old Nov 23rd, 2007, 08:36
welshstew's Avatar
welshstew welshstew is offline
Lead Administrator

SuperMember
Join Date: May 2007
Location: inside the outside
Posts: 1,342
Blog Entries: 13
Thanks: 1
Thanked 4 Times in 4 Posts
[SOLVED] Array sorting

I am still learning ASP functions, so please be gentle with me. I have got a script that sorts a multi-dimensional array Ascending, but I need to switch this to Descending.

Anyway, I've gone and got myself all confuddled, and can't see the wood for the trees. Any help is hugely appreciated.

Code: Select all
Function arraySortDecend( arToSort, sortBy, compareDates )

    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 not compareDates then
                if strComp( arToSort( sortBy, d ), smallestValue ) < 0 Then
                smallestValue = arToSort( sortBy, d )
                smallestIndex = d
                End if
            else
                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
            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
    End Function
__________________
WelshStew
Lead Administrator

tierney rides tboard - uk site | xtreme wales - extreme clothing
If you think I've helped, click the "Thanks"
webforumz - facebook | LinkedIn

Last edited by welshstew; Nov 23rd, 2007 at 08:37. Reason: no asp tag for code...
Reply With Quote