Vb.net MP3播放器随机功能不支持';行不通
我刚开始我的第一个项目,我正在尝试做一个mp3播放器。 不幸的是,当我试图打开一首歌时,我的“随机”导致整个程序崩溃 这是Visual Studio Ultimate 2013中产生的错误:Vb.net MP3播放器随机功能不支持';行不通,vb.net,visual-studio-2012,Vb.net,Visual Studio 2012,我刚开始我的第一个项目,我正在尝试做一个mp3播放器。 不幸的是,当我试图打开一首歌时,我的“随机”导致整个程序崩溃 这是Visual Studio Ultimate 2013中产生的错误: An exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll but was not handled in user code Additional information: I
An exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll but was not handled in user code
Additional information: InvalidArgument=Value of '1' is not valid for 'index'.
请告诉我我的代码有什么问题,这是指向我在Github中的存储库的链接,谢谢
编辑:
这一行是产生错误的代码-
Private Sub wpm_PlayStateChange(sender As Object, e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles wpm.PlayStateChange While shuffle.CheckOnClick = True tempInt = r.Next(0, ListBox1.Items.Count + 1) wpm.URL = ListBox1.Items(tempInt) End While While RepeatToolStripMenuItem1.CheckOnClick = True wpm.URL = currentSong End While End Sub
我认为这是有问题的子项:
Private Sub wpm_PlayStateChange(sender As Object, e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles wpm.PlayStateChange
While shuffle.CheckOnClick = True
tempInt = r.Next(0, ListBox1.Items.Count + 1)
wpm.URL = ListBox1.Items(tempInt)
End While
While RepeatToolStripMenuItem1.CheckOnClick = True
wpm.URL = currentSong
End While
End Sub
线路
tempInt = r.Next(0, ListBox1.Items.Count + 1)
应该是
tempInt = r.Next(0, ListBox1.Items.Count)
此函数的语法是随机的。下一步(min,max),其中min是包含的,max是独占的,即max不包括在生成随机数的过程中。因为您向ListBox1.Items.Count添加了一个(这将是集合的上限加上一个),所以超出了范围。请检查您的迭代代码 我想问题是,你的指数增加了
For Each item As String In My.Computer.FileSystem.GetFiles(txtfolder.Text, Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, "*.mp3")
ListBox1.Items.Add(item)
Next
请在此处包含实际代码的相关部分,并(如果可能)指出错误出现的行。