Search Tools Links Login

Add only unique items to a listbox (no duplicates added). Fast and short without any loops.

Posted: 2002-06-01
By: ArchiveBot
Viewed: 66

Filed Under:

VB6 Code Cache

No attachments for this post


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.

Original Author: Fredrik Schultz

Inputs

StringToAdd = the string to add (if not already exists)
lst = your ListBox

Code

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


Comments on this post

No comments have been added for this post.

You must be logged in to make a comment.