|
-
Jul 26th, 2004, 04:44 PM
#1
Thread Starter
New Member
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.
-
Jul 26th, 2004, 05:09 PM
#2
Frenzied Member
try the .Contains() method:
VB Code:
if box2.contains(an item from box1) then
box2.remove(the item)
i am not at my vs studio right now but I'll try to get better code when I am.
-
Jul 26th, 2004, 05:16 PM
#3
Frenzied Member
hmm, that might not work as i thought. I'm trying right now.
-
Jul 26th, 2004, 05:19 PM
#4
Frenzied Member
VB Code:
If ListBox2.Items.Item(0).Equals(ListBox1.Items.Item(0)) Then
'(CType(ListBox1.Items.Item(0), Control)) Then
MessageBox.Show("Yes")
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|