Help me sort a two - d array

Discussion in 'ASP General' started by Pejo, Aug 6, 2003.

  1. Pejo

    Pejo Guest

    I need help sorting a multidimensional array.


    I have an array myarray(column_no, row_no) it has 5 columns for this
    example I have used 4 rows but there will usually be a couple of hundred.
    Assuming yhey look something like below



    myArray(0,1) = 1.6
    myArray(1,1) =71544
    myArray(2,1) =chewtoy
    myArray(3,1) = 5
    myArray(4,1) = 5
    myArray(5,1) = 0

    myArray(0,2) = 1.9
    myArray(1,2) =43124
    myArray(2,2) =electricfan
    myArray(3,2) = 3
    myArray(4,2) = 2
    myArray(5,2) = 1

    myArray(0,3) = 1.3
    myArray(1,3) =8734
    myArray(2,3) =login
    myArray(3,3) = 5
    myArray(4,3) = 4
    myArray(5,3) = 1

    myArray(0,4) = 1.1
    myArray(1,4) =1624
    myArray(2,4) =off
    myArray(3,4) = 6
    myArray(4,4) = 2
    myArray(5,4) = 4



    Does anyone know of a function I can call that would allow my to resort my
    array based on which column I pass it?

    Thanks for your help.



    There are 10 types of people in this world, those that understand binary,
    and those that don't.
     
    Pejo, Aug 6, 2003
    #1
    1. Advertising

  2. You can write your own sort functions for each column type. OR, you could
    create a custom recordset, instead of an array, and use it instead.
    Recordsets have in-built sort mechanisms you can utilize. I would definitely
    recommend that.

    --
    Manohar Kamath
    Editor, .netBooks
    www.dotnetbooks.com


    "Pejo" <> wrote in message
    news:sS9Ya.2917$...
    > I need help sorting a multidimensional array.
    >
    >
    > I have an array myarray(column_no, row_no) it has 5 columns for this
    > example I have used 4 rows but there will usually be a couple of hundred.
    > Assuming yhey look something like below
    >
    >
    >
    > myArray(0,1) = 1.6
    > myArray(1,1) =71544
    > myArray(2,1) =chewtoy
    > myArray(3,1) = 5
    > myArray(4,1) = 5
    > myArray(5,1) = 0
    >
    > myArray(0,2) = 1.9
    > myArray(1,2) =43124
    > myArray(2,2) =electricfan
    > myArray(3,2) = 3
    > myArray(4,2) = 2
    > myArray(5,2) = 1
    >
    > myArray(0,3) = 1.3
    > myArray(1,3) =8734
    > myArray(2,3) =login
    > myArray(3,3) = 5
    > myArray(4,3) = 4
    > myArray(5,3) = 1
    >
    > myArray(0,4) = 1.1
    > myArray(1,4) =1624
    > myArray(2,4) =off
    > myArray(3,4) = 6
    > myArray(4,4) = 2
    > myArray(5,4) = 4
    >
    >
    >
    > Does anyone know of a function I can call that would allow my to resort my
    > array based on which column I pass it?
    >
    > Thanks for your help.
    >
    >
    >
    > There are 10 types of people in this world, those that understand binary,
    > and those that don't.
    >
    >
    >
    >
     
    Manohar Kamath [MVP], Aug 6, 2003
    #2
    1. Advertising

  3. Try the following to create a recordset on the fly, add data, and sort
    the recordset.




    Dim myObject
    Set myObjects = myObject
    Dim myRecordset
    Set myRecordset =CreateObject("ADODB.RecordSet")
    myRecordset.CursorLocation = 3 'client location
    myRecordset.Fields.Append "myField1", 200, 100 'varchar 100 long
    myRecordset.Fields.Append "myField2", 200, 400 'varchar 400 long
    myRecordset.Open

    For Each myObject In myObjects
    myRecordset.AddNew
    myRecordset.Fields("myField1").Value =
    myObject.myCollection("myField1").value
    myRecordset.Fields("myField2").Value =
    myObject.myCollection("myField2").value
    myRecordset.Update
    Next

    myRecordset.sort = "myField1 " & " DESC"
    myRecordset.MoveFirst

    While Not myRecordset.EOF
    response.write myRecordset.Fields("myField1").Value & ", " &
    myRecordset.Fields("myField2").Value & "<br>
    myRecordset.MoveNext
    Wend




    "Pejo" <> wrote in message news:<sS9Ya.2917$>...
    > I need help sorting a multidimensional array.
    >
    >
    > I have an array myarray(column_no, row_no) it has 5 columns for this
    > example I have used 4 rows but there will usually be a couple of hundred.
    > Assuming yhey look something like below
    >
    >
    >
    > myArray(0,1) = 1.6
    > myArray(1,1) =71544
    > myArray(2,1) =chewtoy
    > myArray(3,1) = 5
    > myArray(4,1) = 5
    > myArray(5,1) = 0
    >
    > myArray(0,2) = 1.9
    > myArray(1,2) =43124
    > myArray(2,2) =electricfan
    > myArray(3,2) = 3
    > myArray(4,2) = 2
    > myArray(5,2) = 1
    >
    > myArray(0,3) = 1.3
    > myArray(1,3) =8734
    > myArray(2,3) =login
    > myArray(3,3) = 5
    > myArray(4,3) = 4
    > myArray(5,3) = 1
    >
    > myArray(0,4) = 1.1
    > myArray(1,4) =1624
    > myArray(2,4) =off
    > myArray(3,4) = 6
    > myArray(4,4) = 2
    > myArray(5,4) = 4
    >
    >
    >
    > Does anyone know of a function I can call that would allow my to resort my
    > array based on which column I pass it?
    >
    > Thanks for your help.
    >
    >
    >
    > There are 10 types of people in this world, those that understand binary,
    > and those that don't.
     
    Howard Rothenburg, Sep 6, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GenxLogic
    Replies:
    3
    Views:
    1,285
    andrewmcdonagh
    Dec 6, 2006
  2. rkk
    Replies:
    9
    Views:
    812
    CBFalconer
    Sep 24, 2006
  3. Navin
    Replies:
    1
    Views:
    698
    Ken Schaefer
    Sep 9, 2003
  4. GIMME
    Replies:
    5
    Views:
    186
    Thomas 'PointedEars' Lahn
    Jul 26, 2004
  5. Domenico Discepola

    multi-field array sort using Sort::Fields method

    Domenico Discepola, Apr 27, 2004, in forum: Perl Misc
    Replies:
    6
    Views:
    302
    Uri Guttman
    Apr 28, 2004
Loading...

Share This Page