by Fredrik Schultz (2 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (11 Votes)
Use this method to avoid adding an item to a ListBox that already exists.
It's a lot faster and shorter than submissions that uses loops etc.
Inputs
StringToAdd = the string to add (if not already exists)
lst = your ListBox
Private Sub AddUnique(StringToAdd As String, lst As ListBox)
lst.Text = StringToAdd
If lst.ListIndex = -1 Then
'it does not exist, so add it..
lst.AddItem StringToAdd
End If
End Sub
No comments have been posted about Add only unique items to a listbox (no duplicates added). Fast and short without any loops.. Why not be the first to post a comment about Add only unique items to a listbox (no duplicates added). Fast and short without any loops..