Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multi-Dimensional Array Sorting HELP!

    I am trying to sort a multidimensional array.

    I am using the following code to do it:

    Code:
    <%
    '============================================== 
    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:

    Code:
    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?

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    what line number is the error on?

  • #3
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #4
    Regular Coder
    Join Date
    Sep 2007
    Posts
    120
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Please post the contents of the array and the desired output.

    Tom

  • #5
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Tom...

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

    Code:
    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

    Code:
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •