Results 1 to 3 of 3

Thread: What is wrong with this bubble sort routine?

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    derby,UK
    Posts
    38
    i am trying to sort records from a file (12 fields) in order of the first field, but even though it works after clicking the button about ten times, i cant get the damn thing to do it first time without adding another for...next loop, doing this would resolve the problem of the first field sort, but if i want to sort by another field i need to change the loop size.

    well heres the code:
    ->->->->->->->->->->->->->
    Function SortRecords(Field)
    ' This is the sort code, this sorts the records in order of the
    'passed parameter.
    On Error GoTo ENDOFFUNCTION

    If ArrayCounterPF = 0 Then
    MsgBox "Norecords to sort!", vbCritical
    Exit Function
    Else
    End If

    Do
    Sorted = True

    For counterx = 1 To ArrayCounterPF
    If ArrayDataPF(Field, counterx) > ArrayDataPF(Field, counterx + 1) Then
    '"sorting..."
    For fieldnumber = 1 To 12

    temp = ArrayDataPF(fieldnumber, counterx + 1)
    ArrayDataPF(fieldnumber, counterx + 1) = ArrayDataPF(fieldnumber, counterx)
    ArrayDataPF(fieldnumber, counterx) = temp

    Next fieldnumber
    Sorted = False
    Else
    End If
    Next counterx

    Loop Until Sorted = True

    ENDOFFUNCTION:
    End Function

    ->->->->->->->->->->

    the function is call from a list box, when the feild is selected from list box, the index is passed to the function (Field).

    Please help, its been bugging me for hours!!!!!

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Can you re-post the code with all the variables declared so I can so exactly what we're working with.


    Please....
    Mark
    -------------------

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    derby,UK
    Posts
    38
    its ok, i've fixed the problem. i forgot to loop the passesd parameters.

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