Return to Snippet

Revision: 11950
at February 25, 2009 06:23 by Joshnolan118


Initial Code
Public Sub SortNames()
    Dim Swapped As Boolean
    Dim J, I As Byte
    Dim tmpUser As UserType
    
    J = NumUsers - 1
    
    Do
        J = J - 1
        Swapped = False
        For I = 0 To J
            If User(I).Surname > User(I + 1).Surname Or _
                (User(I).Surname = User(I + 1).Surname And _
                User(I).Forename > User(I + 1).Forename) Then
                
                'Out of order so swap
                Swapped = True
                tmpUser = User(I)
                User(I) = User(I + 1)
                User(I + 1) = tmpUser
            End If
      Next I
    Loop Until Swapped = False Or J = 1

End Sub

Initial URL

                                

Initial Description

                                

Initial Title
vb6 - Bubble Sort - Sort by Surename and Forename

Initial Tags
sort

Initial Language
Visual Basic