Link to home
Start Free TrialLog in
Avatar of 2helpornot2help
2helpornot2help

asked on

Better Sort Algorithm

  I am using a simple "Bubble Sort" to sort the elements in a MSFlexGrid.  This works very well for about 40 rows of data.  If you have more data, the user will notice the lag a lot more.  I was hoping that there is a "Quick Sort" algorithm for a MSFlexGrid that I could use.  I only need to sort the data in the grid based on the FieldNumber (Column) of the grid.  Below is my simple procedure for sorting the grid.  If you have a better algorithm (Quick Sort) or if you could make improvements in the way that I programmed the algorithm, it would be great!!  Thanks in advance.

Here is my simple Bubble Sort

Sub SortField(ByVal FieldNumber As Integer)

    Dim Continue As Boolean
    Dim i As Integer
    ReDim TempString(frmMain.msflexgrid1.Cols) As String
    Dim TempField As String
   
    Screen.MousePointer = 11
    With frmMain.msflexgrid1
    .Visible = False
    Continue = True
    Do While Continue = True
        Continue = False
        .Row = 1
        .Col = FieldNumber
        Do While .Row < .Rows - 1
            TempField = .Text
            .Row = .Row + 1
            If .Text < TempField Then
                For j = 0 To .Cols - 1
                    .Col = j
                    TempString(j) = .Text
                Next j
               
                For j = 0 To .Cols - 1
                    .Col = j
                    .Row = .Row - 1
                    TempField = .Text
                    .Row = .Row + 1
                    .Text = TempField
                Next j
               
                .Row = .Row - 1
                For j = 0 To .Cols - 1
                    .Col = j
                    .Text = TempString(j)
                Next j
                .Row = .Row + 1
                Continue = True
            End If
        Loop
    Loop
    .Visible = True
    End With
    Screen.MousePointer = 1
End Sub
ASKER CERTIFIED SOLUTION
Avatar of hansbos
hansbos

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 2helpornot2help
2helpornot2help

ASKER

Thanks A lot!!