Help me sort a two - d array

Ask a Question related to ASP, Design and Development.

  1. #1

    Default Help me sort a two - d array

    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 Guest

  2. Similar Questions and Discussions

    1. Sort Array in datagrid
      How do you sort an array in your datagrid? I always want to be able to sort my array by an instance number. If you add a new instance I want it to...
    2. Sort Array
      Hi Can anyone give me a pointer on sorting this array below #curr.getRateCurrencyCode()# (lowest to highest values) <cfloop from ='1' to...
    3. sort array by key
      Hi, What I want is simple, but I can't figure it out at the moment. Let's say this is an array names $matches: Array ( => Array (
    4. Sort a 2D array
      Hello, I have a 2D array which I would like to sort. I take a simple example: $tab = 'toto';$tab = 'toto'; $tab = 'aaaa';$tab = 'titi'; $tab...
    5. sort w/o using an array
      I am trying to figure out if there is a way to do a sort that doesn't involve putting an entire file in memory. This kind of thing is available in...
  3. #2

    Default Re: Help me sort a two - d array

    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
    [url]www.dotnetbooks.com[/url]


    "Pejo" <pottymouthed@hotmail.com> wrote in message
    news:sS9Ya.2917$_a4.591617@news20.bellglobal.com.. .
    > 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] Guest

  4. #3

    Default Re: Help me sort a two - d array

    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" <pottymouthed@hotmail.com> wrote in message news:<sS9Ya.2917$_a4.591617@news20.bellglobal.com> ...
    > 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 Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139