By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,197 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,197 IT Pros & Developers. It's quick & easy.

sorting

P: 2
I don't know how to sort this one. Can you please help me?

Using array, and using the bubble sort...

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Public ctr As String
  3.  
  4. Private Sub cmdAdd_Click()
  5. Dim a As Integer
  6. Dim abc As String
  7.  
  8. a = InputBox("Number")
  9.  
  10. For a = 1 To a
  11.     abc = InputBox("name")
  12.     List1.AddItem abc
  13. Next a
  14.     cmdAdd.Enabled = False
  15.     ctr = a
  16.  
  17. End Sub
  18.  
  19. Private Sub cmdsort_Click()
  20.     Dim x As Integer
  21.     Dim y As Integer
  22.     Dim compare1 As String
  23.     Dim compare2 As String
  24.  
  25.     x = 0
  26.     y = 0
  27.  
  28.     compare2 = List1.List(y + 1)
  29.     compare1 = List1.List(y)
  30.  
  31.     While x <= ctr - 1
  32.         If x = ctr Then
  33.             List2.AddItem compare1
  34.         Else
  35.             If compare1 <= compare2 Then
  36.                 compare1 = compare1
  37.                 x = x + 1
  38.  
  39.             List2.AddItem compare1
  40.                 y = y + 1
  41.                 compare2 = List1.List(y + 1)
  42.                 compare1 = List1.List(y)
  43.             Else
  44.                 compare1 = compare2
  45.     End If
  46. End If
  47.  
  48. Wend
  49.  
  50.  
  51. End Sub
Sep 17 '07 #1
Share this Question
Share on Google+
2 Replies


hariharanmca
100+
P: 1,977
I think we have sort option in listBox itself!

Set Property Sorted = True in property window.
Sep 17 '07 #2

Expert 5K+
P: 8,434
As Hari pointed out, the ListBox control has a Sorted property which may solve your issue. The thing is, you haven't actually told us what the problem is.
Sep 18 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.