Search Tools Links Login

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


Visual Basic 6, or VB Classic

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

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 103 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.