Results 1 to 2 of 2

Thread: Duplicates

  1. #1
    Join Date
    Aug 2004

    Unanswered: Duplicates

    Is there a way to kind of say:

    Private Sub Text1_Change()
    If (Object exists In listbox Or an Object that begins With a certain letter/letters exists) Then
    If text1.text = "first few letters of the object" Then
    text1.text = ""
    End If
    End If
    End Sub

    Basically, this should stop the user from entering a piece of data twice because it they try to write it in the textbox if will automatically clear. Please imagine that there is only one object avaliable to enter. I will duplicate the code for the other avaliable items... it will be easier for me to understand later.

    Thanks in advance for any help!


  2. #2
    Join Date
    Aug 2004
    Don't worry I found a suitable code:

    ListIndex = 0
    Do Until ListIndex = List2.ListCount
      'With this index, loop through all of the elements of the listbox in reverse order,
      'removing any element that has the same text as this one.
      TextToMatch = List2.List(ListIndex)  'Text of this item to check duplicates for
      For LV = List2.ListCount - 1 To ListIndex + 1 Step -1  'loop through remaining items to check for duplicates.
      'Notice: LB.ListCount -1 is the index of the last item in the listbox.
      'LBIndex + 1 is the item immediately after the one that we are checking duplicates on.
        If List2.List(LV) = TextToMatch Then
          'We've found a duplicate!  Delete it and then count it.
          List2.RemoveItem LV
          NumofDuplicates = NumofDuplicates + 1
        End If
      Next LV
      'Go to the next item: all duplicates of this have been found.
      ListIndex = ListIndex + 1

Posting Permissions

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