ddprogrammer
11-13-2007, 08:15 AM
I am trying to sort a multidimensional array.
I am using the following code to do it:
<%
'==============================================
function arraySort( 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%>
This is the code I am calling it from:
myArray=arraySort(myArray,2,false)
But I am getting this error:
Microsoft VBScript runtime error '800a000d'
Type mismatch
I know that the array is created properly because I am able to display its contents without any trouble if I skip the sorting step.
What am I doing wrong?
I am using the following code to do it:
<%
'==============================================
function arraySort( 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%>
This is the code I am calling it from:
myArray=arraySort(myArray,2,false)
But I am getting this error:
Microsoft VBScript runtime error '800a000d'
Type mismatch
I know that the array is created properly because I am able to display its contents without any trouble if I skip the sorting step.
What am I doing wrong?