Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21842

[RESOLVED] Going through a listbox and removing all items that are the same.

$
0
0
Hi there all! I am finishing up a game that demonstrates probability to students, and what I have is a listbox that is randomized, then the prog picks an item to add to a label caption. Then it removes that one item that was in the label caption. I was wondering if there was a way to remove all instances of whatever was in that label caption from the listbox?

I use this to randomly pick an item and it works GREAT.

VB Code:
  1. Public Sub PickAWinnerNOW()
  2. Dim lIndex As Long
  3.    If StudentList.ListCount Then
  4.       lIndex = Int(Rnd * StudentList.ListCount)
  5. 'This is where the program will add the item to the label caption
  6.       TicketDrawWinnerLBL.Caption = StudentList.List(lIndex)
  7.  
  8.   'Now have the program remove the item from the listbox
  9.       StudentList.RemoveItem lIndex
  10.    End If

Now this will definitely remove the item, but as mentioned before I would like to remove all instances of that item. In an earlier thread, advice for a loop was given, which is great as a loop should go through the listbox and look/remove the label caption, but how do I set it up?

Dim i As String (would it be a string since it is a name I am looking for)
For i = 1 To CInt(TicketDrawWinnerLBL.Caption)
StudentList.RemoveItem TicketDrawWinnerLBL.Caption
Next

I don't know if this is important to mention, but the list has by this point been mixed up, so the items are not all together, for ex: the name BOB would be mixed up with the other student names. :) Thanks for your help!!!

Viewing all articles
Browse latest Browse all 21842

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>