vb6 - Bubble Sort - Sort by Surename and Forename


/ Published in: Visual Basic
Save to your folder(s)



Copy this code and paste it in your HTML
  1. Public Sub SortNames()
  2. Dim Swapped As Boolean
  3. Dim J, I As Byte
  4. Dim tmpUser As UserType
  5.  
  6. J = NumUsers - 1
  7.  
  8. Do
  9. J = J - 1
  10. Swapped = False
  11. For I = 0 To J
  12. If User(I).Surname > User(I + 1).Surname Or _
  13. (User(I).Surname = User(I + 1).Surname And _
  14. User(I).Forename > User(I + 1).Forename) Then
  15.  
  16. 'Out of order so swap
  17. Swapped = True
  18. tmpUser = User(I)
  19. User(I) = User(I + 1)
  20. User(I + 1) = tmpUser
  21. End If
  22. Next I
  23. Loop Until Swapped = False Or J = 1
  24.  
  25. End Sub

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.