Need Help one more time

Cabose

Active member
Joined
Oct 18, 2006
Messages
39
Programming Experience
Beginner
I am making a media player and i want to make a shuffle button that will randomly select a song in my playlist (listbox).

Thanks,
Cabose
 
the code from the msdn thing is a little confusing could you type a small code that would do that for me?

~Cabose
 
Little simpler:

Realize though, that if your set is small enough it will be effectivly impossible for the computer to get you a "random" number.

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ListBox1.Items.Add([/SIZE][SIZE=2][COLOR=#800000]"asdf"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ListBox1.Items.Add([/SIZE][SIZE=2][COLOR=#800000]"asdf"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ListBox1.Items.Add([/SIZE][SIZE=2][COLOR=#800000]"asdf"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ListBox1.Items.Add([/SIZE][SIZE=2][COLOR=#800000]"asdf"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myRandom [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Random()
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] RandomNumber [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = myRandom.Next(1, [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ListBox1.Items.Count)
MessageBox.Show(RandomNumber)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]
 
How would i make sure it doesnt select the same item when it goes to the next song. For example when i have it on shuffle and i click the next song button sometimes it selects the same song how do i stop that?

~Cabose
 
You'll need to store some identifier for the song your currently playing (presumably the index of the song in the listbox). Then when the user clicks RandomSong check that the number returned isnt the same as the current index. If it is, select another random number.
 
Back
Top