We help IT Professionals succeed at work.

# Better Sort Algorithm

on
292 Views
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
Comment
Watch Question

## View Solution Only

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)

Commented:
Thanks A lot!!
Unlock the solution to this question.