VB icon

Randomize ListBox Items

Email
Submitted on: 8/26/2015 2:03:10 AM
By: Thomas Ault 
Level: Intermediate
User Rating: Unrated
Compatibility: VB.NET
Views: 3516
 
     Randomize Listbox Items. I made this to generate a random list for a mp3 player. I added a loop so the listbox gets a good mix up.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Randomize ListBox Items
// Description:Randomize Listbox Items. I made this to generate a random list for a mp3 player. I added a loop so the listbox gets a good mix up.
// By: Thomas Ault
//**************************************

Try
Dim X As Integer = 0
Dim I As Integer
Dim str As String = ""
Listbox1.Sorted = False
Listbox1.BeginUpdate()
Do
For C = 0 To Listbox1.Items.Count
Randomize()
I = CInt(Int(C) * Rnd())
str = Listbox1.Items(I)
Listbox1.Items.RemoveAt(I)
Listbox1.Items.Add(str)
Next
X += 1
Loop Until X = 3
Listbox1.EndUpdate()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
'Add Listbox1.Sorted=True to a button click event to reorder the list


Other 4 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.