i want to check the item in list box whether has repeated or not......
how to do it?
Printable View
i want to check the item in list box whether has repeated or not......
how to do it?
To check the uniqueness of an Item in a list box I think you need to add an identifier in the ItemData property fpr each Item. You can then access this value to check for duplicates.
Below is an example:
Hope this helpsCode:
listbox1.AddItem "No 1"
listbox1.ItemData(listbox1.NewIndex) = 1
listbox1.AddItem "No 2"
listbox1.ItemData(listbox1.NewIndex) = 2
Dim i As Long
For i = 0 To listbox1.ListCount - 1
If listbox1.ItemData(i) = 5 Then
MsgBox "No 5 exists"
Else
listbox1.AddItem "No 5"
listbox1.ItemData(listbox1.NewIndex) = 5
End If
Next
Do you mean if there are duplicate entries of the same item?Quote:
Originally Posted by chxxangie
Quote:
Originally Posted by Hack
yup....
how are you loading items into the list...if you are checking with a text box then use like thisCode:For i = 0 To List1.ListCount - 1
If Text1.Text = List1.List(i) Then
MsgBox "Duplicate: " & List1.List(i)
End If
Next
do a search for LB_FINDSTRINGEXACT
Track the index each time an item in the list box is clicked on. Use a simple integer vector array that changes to True when it occurs.
Optionally, you could also increment the array element to count the number of times the item has been clicked on in the list box. That gives you more information.
I have some questions.
Do you want to prevent duplicates? If so, take a look at ganeshmoorthy's post?
Do you want to allow duplicates, but flag them? If so, there is code for that as well.