Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Oct 24, 2001



Application Security Testing: An Integral Part of DevOps

Switch a Combo Box Sort from Alpha to Number

Don't forget to turn off the .sorted property on the combo box before calling!
ResortCboFromAlphaToNum cboAbc

Public Sub ResortCboFromAlphaToNum(cc As ComboBox)
    'resorts given combobox from alpha sort (usual) 
to numeric sort
    'e.g.  1,11,2,22 >> 1,2,11,22
    Dim ListStrArr() As String
    Dim ItemDataLngArr() As Long
    Dim tmpLng As Long
    Dim tmpStr As String

    Dim i As Integer
    Dim j As Integer
    Dim ListCountInt As Integer

    Dim LargestValLng As Long
    Dim ArrayPosInt As Integer
    ListCountInt = cc.ListCount

    If ListCountInt = 0 Then Exit Sub

    ReDim ListStrArr(ListCountInt - 1)
    ReDim ItemDataLngArr(ListCountInt - 1)

    For i = 0 To ListCountInt - 1
        ListStrArr(i) = cc.List(i)
        ItemDataLngArr(i) = cc.ItemData(i)
    'note, sorting operation is MUCH faster against 
arrays than with combo object
    'uses exchange sort, not optimal, but adequate
    For i = 0 To ListCountInt - 1
        LargestValLng = 0
        For j = i To ListCountInt - 1
            If LargestValLng <= val(ListStrArr(j)) 
                LargestValLng = val(ListStrArr(j))
                tmpStr = ListStrArr(i)
                tmpLng = ItemDataLngArr(i)

                ListStrArr(i) = ListStrArr(j)
                ItemDataLngArr(i) = ItemDataLngArr(j)

                ListStrArr(j) = tmpStr
                ItemDataLngArr(j) = tmpLng
            End If
        Next 'j
    Next 'i

    For i = 0 To ListCountInt - 1
        cc.List(i) = ListStrArr(ListCountInt - 1 - i)
        cc.ItemData(i) = ItemDataLngArr
(ListCountInt - 1 - i)
End Sub
Patrick Marshall
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date