...

# Multi-Dimensional Array Sorting HELP!

ddprogrammer
11-13-2007, 09: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?

11-13-2007, 03:41 PM
what line number is the error on?

ddprogrammer
11-13-2007, 08:13 PM
The error is on line 100, which is just the line where I am calling the function. It doesnt even seem to make it inside!

Whatever Jr.
11-14-2007, 12:57 PM
Please post the contents of the array and the desired output.

Tom

ddprogrammer
11-15-2007, 09:01 AM
Thanks Tom...

The array is really long. Here is a sample of it:

myArray(0,1) = Denom
myArray(1,1) = JCCA
myArray(2,1) = Camp One
myArray(3,1) = 1188
myArray(4,1) = 1188
myArray(0,2) = None
myArray(1,2) = JCCA
myArray(2,2) = Camp Two
myArray(3,2) = 0
myArray(4,2) = 0
myArray(0,3) = Denom 2
myArray(1,3) = Independent
myArray(2,3) = Three Camp
myArray(3,3) = 595
myArray(4,3) = 595
myArray(0,4) = Non-denominational
myArray(1,4) = JCCA
myArray(2,4) = Camp Four
myArray(3,4) = 563
myArray(4,4) = 563
myArray(0,5) = None
myArray(1,5) = JCCA
myArray(2,5) = Camp Mountain
myArray(3,5) = 0
myArray(4,5) = 0

The output should be

Non-denominational,JCCA,Camp Four,563,563
None,JCCA,Camp Mountain,0,0
Denom,JCCA,Camp One,1188,1188
None,JCCA,Camp Two,0,0
Denom 2,Independent,Three Camp,595,595

meaning sorted by the third item in the row, or 2 in the array.

Thanks!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum