You say your code currently sorts the array ascending
I believe
but have not checked nor properly read your code that the following modified code will work.
- 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( smallestValue, arToSort( sortBy, d ) ) < 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", smallestValue, arToSort( sortBy, d ) ) > 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
I cannot stress enough that this is just my cursory glance at it.
Personally when I am trying to create a piece of code I start out writing out how I would do it manually in simple english then work on converting that to code with some refinements along the way.
I find that it helps my understanding of what I'm doing.