Results 1 to 8 of 8

Thread: check repeated item in list box

  1. #1

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    check repeated item in list box

    i want to check the item in list box whether has repeated or not......
    how to do it?

  2. #2
    Junior Member
    Join Date
    Mar 2007
    Posts
    19

    Re: check repeated item in list box

    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:
    Code:
     
        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
    Hope this helps

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: check repeated item in list box

    Quote Originally Posted by chxxangie
    i want to check the item in list box whether has repeated or not......
    how to do it?
    Do you mean if there are duplicate entries of the same item?

  4. #4

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    Re: check repeated item in list box

    Quote Originally Posted by Hack
    Do you mean if there are duplicate entries of the same item?

    yup....

  5. #5
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: check repeated item in list box

    how are you loading items into the list...if you are checking with a text box then use like this
    Code:
        For i = 0 To List1.ListCount - 1
            If Text1.Text = List1.List(i) Then
                MsgBox "Duplicate: " & List1.List(i)
            End If
        Next
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: check repeated item in list box

    do a search for LB_FINDSTRINGEXACT

  7. #7
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: check repeated item in list box

    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.
    Last edited by Code Doc; Mar 9th, 2007 at 10:00 AM.
    Doctor Ed

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: check repeated item in list box

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width