Results 1 to 4 of 4

Thread: Comparing/Removing Data

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Location
    Connecticut
    Posts
    7

    Comparing/Removing Data

    I have two listboxes that I need to compare. One contains some numbers between 1-11000; the second box contains all numbers 1-11000.

    What I'm trying to do is take a string from the first list and remove it from the second list.
    Code:
        Dim i As Short
        Dim x As Short
    
            For x = 0 To List2.Items.Count - 1
                For i = 0 To List1.Items.Count - 1
                    If List1.Items(i) = List2.Items(x) Then
                        List2.Items.Remove(x)
                    End If
                Next i
            Next x
    That is the code that I have, but it doesn't function right. I don't get any errors, but it also doesn't remove the numbers from list1.

    I forgot to add: If you couldn't tell, I'm a complete newb.
    Last edited by Vredig; Jul 26th, 2004 at 04:48 PM.

  2. #2
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    try the .Contains() method:

    VB Code:
    1. if box2.contains(an item from box1) then
    2. box2.remove(the item)

    i am not at my vs studio right now but I'll try to get better code when I am.

  3. #3
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    hmm, that might not work as i thought. I'm trying right now.

  4. #4
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    VB Code:
    1. If ListBox2.Items.Item(0).Equals(ListBox1.Items.Item(0)) Then
    2.             '(CType(ListBox1.Items.Item(0), Control)) Then
    3.             MessageBox.Show("Yes")
    4.         End If

    that compares the two.

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