Public Function sortListBox(thisList As ListBox)
Dim firstCounter As Long, temp As String, secondCounter
'loop from first to last item
' this will start sorting the items from the second item.
For firstCounter = 1 To thisList.ListCount - 1
'loop from the firstCounter+1 item to last item
For secondCounter = firstCounter + 1 To thisList.ListCount - 1
'check if the value is greater
If Val(thisList.List(firstCounter)) > Val(thisList.List(secondCounter)) Then
'swap the items here
'----------------------------------------------
temp = thisList.List(firstCounter)
thisList.List(firstCounter) = thisList.List(secondCounter)
thisList.List(secondCounter) = temp
'----------------------------------------------
End If
Next
Next
End Function
Private Sub Form_Load()
List1.AddItem "1"
List1.AddItem "2"
List1.AddItem "10"
List1.AddItem "45"
List1.AddItem "7"
List1.AddItem "70"
List1.AddItem "46"
sortListBox List1
End Sub