Results 1 to 4 of 4

Thread: sorting an array

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Wellington, NZ
    Posts
    267

    sorting an array

    Hi

    I have a dynamic array. Each row contains 7 numeric values. I want to sort this array by field7 within field6 within field5, etc up to field1.

    My first thought is to redim the array to give an empty row at the end, and use it to shiffle out of sequence rows. Or I could just dump the out-of-sequence row data into other fields.

    What do you think ?

    Regards
    Robert

  2. #2
    New Member
    Join Date
    Oct 2005
    Posts
    10

    Re: sorting an array

    Give it a try and see if it works.

    If it does i think you are correct.

    If not i think you are wrong


  3. #3
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: sorting an array

    Quote Originally Posted by RobertLees
    Hi

    I have a dynamic array. Each row contains 7 numeric values. I want to sort this array by field7 within field6 within field5, etc up to field1.

    My first thought is to redim the array to give an empty row at the end, and use it to shiffle out of sequence rows. Or I could just dump the out-of-sequence row data into other fields.

    What do you think ?

    Regards
    Robert
    I'm an old time COBOL programmer and we sometimes used a bubble sort. I Googled it and found a Visual Basic version. Here is the link which contains some forms to test the results.

    http://zone.ni.com/devzone/conceptd....256E5C000030C6

    Here is the code.

    VB Code:
    1. Public Sub BubbleSort(ByRef sortArray() As Integer)
    2. Dim i As Integer
    3. Dim j As Integer
    4. Dim Temp As Integer
    5. For i = LBound(sortArray) To UBound(sortArray)
    6. For j = LBound(sortArray) To (UBound(sortArray) - i - 1)
    7. If sortArray(j + 1) < sortArray(j) Then
    8. Temp = sortArray(j) 'swap if the two items
    9. sortArray(j) = sortArray(j + 1) 'are out of order
    10. sortArray(j + 1) = Temp
    11. End If
    12. Next j
    13. Next i
    14. End Sub

    If this doesn't fit the bill Google on "bubble sort" some more.


  4. #4
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    Re: sorting an array

    You could google for sorting methods and VB source code to find a lot of improved sorting methods as well
    why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
    for every question you ask provide an answer on another thread.

Posting Permissions

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



Click Here to Expand Forum to Full Width