Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alphabetical Sorting

Status
Not open for further replies.

Stopher

Programmer
Jan 12, 2002
29
US
Does anyone know of a way to sort strings alphabetically? Basically I have an array of strings that I want to rearrange in alphabetical order.

Thanx,
Da Stopher
 
The array in this example is called 'arr()' change it to your array name!

Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
Dim strFileName As String
'Sort
For i = 0 To UBound(arr()) - 1
For j = 0 To UBound(arr()) - 1 - i
If arr(j + 1) < arr(j) Then
strFileName = arr(j)
arr(j) = arr(j + 1)
arr(j + 1) = strFileName
End If
Next j
Next i

'Just to show the alphabetical list
List1.Clear 'Normal list .. Sorted = False
For j = 0 To UBound(arr())
List1.AddItem arr(j)
Next j

End Sub
 
Look up Shell sort, Insertion Sort, Quick Sort, Bubble sort if you want the algorithms. If you want more detail, you need to be more specific in your question and let us know when the assignment is due.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top