How to Sort a Multi-Dimensional Array - And We Proceed with Our Checking
(Page 3 of 4 )
If we have genuine dates, we proceed with our checking, by using the ASP dateDiff() function. Similar to strComp(), this function produces positive or negative integers; however, they're based on the difference in the time frame you specify, and we will specify days (“d”).
if not isDate( smallestValue ) then
arraySort = arraySort( arToSort, sortBy, false)
exit function
else
if dateDiff( "d", arToSort( sortBy, d ), smallestValue ) > 0 Then '=== no carriage return
smallestValue = arToSort( sortBy, d )
smallestIndex = d
End if
end if
end if
Next
Now, we're finished checking the whole array for this specific item, and before we move on the next, we see if anything smaller has been found. If so, then we'll swap the current item for the smallest item found. And of course, since we're dealing with multiple dimensions, we have to loop through them all, and swap all of them, to make sure that we maintain the complete array.
if smallestIndex <> c Then
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
Next: Conclusion >>
More ASP Articles
More By Justin Cook