Author |
Message |
tupac
|
Posted: Thu Mar 16, 2006 3:38 pm Post subject: Checking items in a list |
|
|
how do you check if an item in a list is the same as another item in the same list?
ex:
_____________
|item1 < same |
|item2 |
|item3 |
|item1 < same |
| |
|____________| |
|
|
|
|
|
Sponsor Sponsor
|
|
|
tupac
|
Posted: Thu Mar 16, 2006 3:40 pm Post subject: (No subject) |
|
|
o, and also, if the 2 items are the same, how do you get rid of the latest one that showed up. |
|
|
|
|
|
pavol
|
Posted: Thu Mar 16, 2006 5:45 pm Post subject: (No subject) |
|
|
well you could use a for loop to cycle through the data in the list like this;
code: | For i = 0 To lstList.ListCount - 1
For j = i + 1 To lstListCount
If lstList.List (i) = lstList.List (j) Then
lstList.RemoveItem (j)
End If
Next j
Next i | i only hope this code works cuz i just thought it up. if it doesn't it should be something like what i just wrote.
anyways, i hope it helps |
|
|
|
|
|
tupac
|
Posted: Fri Mar 17, 2006 10:16 am Post subject: (No subject) |
|
|
well... that didnt help much... but i do get where ure comin from. may-b im duin it worng... i setup a timer w/ an interval of 1, and put ure code in the Private Sub Timer2_Timer()... is that how its supposed to work?? anyway, thnx for what u gave me so far... just tell me if wat im duin is rite (puttin it into a timer), and if so then ill try 2 tweak some more with it... |
|
|
|
|
|
pavol
|
Posted: Fri Mar 17, 2006 11:14 am Post subject: (No subject) |
|
|
i should think that's pretty much right to put it in a timer. makes sense, but you don't really need to check it that often. try putting the code after your code that adds an item to the list
so, something like this:
code: | lstList.AddItem whatever
For i = 0 To lstList.ListCount - 1
For j = i + 1 To lstListCount
If lstList.List (i) = lstList.List (j) Then
lstList.RemoveItem (j)
End If
Next j
Next i | so taht means as soon as the user adds an item that's the same as another item in the list it should be taken away |
|
|
|
|
|
cool dude
|
Posted: Fri Mar 17, 2006 11:27 am Post subject: (No subject) |
|
|
yes pavol has the right idea! NO do not use a timer there is absolutely no point at all to use a timer in this case |
|
|
|
|
|
tupac
|
Posted: Fri Mar 17, 2006 1:31 pm Post subject: (No subject) |
|
|
well, actually there is a point... cuz im workin on a multi-user chat program, and i need to check if new users are loggin on very frequently. |
|
|
|
|
|
pavol
|
Posted: Fri Mar 17, 2006 3:00 pm Post subject: (No subject) |
|
|
well if you need it to be checked every so often then put the code in a timer, but i still think that you could do without it |
|
|
|
|
|
Sponsor Sponsor
|
|
|
tupac
|
Posted: Sat Mar 18, 2006 2:03 pm Post subject: (No subject) |
|
|
well, wat i did is after i send the msg (name) i do the code:
code: |
For i = 0 To lstNames.ListCount - 1
For j = i + i To lstNames.ListCount
If lstNames.List(i) = lstNames.List(j) Then
lstNames.RemoveItem (j)
End If
Next j
Next i |
and now it doesnt clogg up the list... but the words continue on down for about 4 - 5 lines... and they go in a line like so:
code: |
____________
|ddkddkddk....|
|ddkddkddk....|
|ddkddkddk....|
|ddkddlkddk...|
|___________| |
|
|
|
|
|
|
|