Results 1 to 5 of 5
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    sort item in combobox... (2000 sr 1)

    Found this 2 routin wath you think?
    Other way are welcome, naturally..
    Tks.

    Sub BubbleSortCombo(myCombo As MSForms.ComboBox)

    Dim iFirst As Integer, iLast As Integer
    Dim iCnt1 As Integer, iCnt2 As Integer
    Dim sTemp As String
    With myCombo
    If .ListCount = 0 Then Exit Sub
    iFirst = 0
    iLast = .ListCount - 1
    For iCnt1 = iFirst To iLast - 1
    For iCnt2 = iCnt1 + 1 To iLast
    If .List(iCnt1) > .List(iCnt2) Then
    sTemp = .List(iCnt2)
    .List(iCnt2) = .List(iCnt1)
    .List(iCnt1) = sTemp
    End If
    Next iCnt2
    Next iCnt1
    End With
    End Sub
    Sub BubbleSort(List)

    Dim First As Integer, Last As Integer
    Dim i As Integer, j As Integer
    Dim Temp

    With Me.ComboBox1

    First = LBound(.List)
    Last = UBound(.List)

    For i = First To Last - 1
    For j = i + 1 To Last
    If .List(i) > .List(j) Then
    Temp = .List(j)
    .List(j) = .List(i)
    .List(i) = Temp
    End If
    Next j
    Next i

    End With
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: sort item in combobox... (2000 sr 1)

    As long as the number of items in the list is not too large, bubble sort works OK, and it is the easiest sorting algorithm.
    If you have thousands of items, there are other algorithms that are much faster.

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: sort item in combobox... (2000 sr 1)

    oK... tKS.
    But i can use the first or second routine?

    this
    Sub BubbleSortCombo(myCombo As MSForms.ComboBox)

    or this
    Sub BubbleSort(List)

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: sort item in combobox... (2000 sr 1)

    You can use the first procedure to sort any combo box. For example, if you want to sort ComboBox1, you use

    BubbleSortCombo Me.ComboBox1

    and if you want to sort ComboBox37, you use

    BubbleSortCombo Me.ComboBox37

    The second procedure should actually be defined as

    Sub BubbleSort()

    since the list argument isn't used. It sorts ComboBox1 only, it cannot be used to sort other combo boxes.

  5. #5
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: sort item in combobox... (2000 sr 1)

    TKS...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •