所以我尝试创建一个非常简单的轮盘赌游戏,将每个可能的结果创建为单独的标签,但是在运行我的代码时,我会看到未处理的异常,我可以看到它来自哪里程度。
但是我不知道该怎么做才能使这项工作,我是编程的新手,所以任何建议都会很棒。谢谢,这是我的代码:
功能代码:
Public Class Random_Number_Gen
Public Function GetRandom()
Dim Min As Integer = 0
Dim Max As Integer = 37
Static Generator As New System.Random()
Return Generator.Next(Min, Max)
End Function
结束班
班级代码:
Public Class Roulette
Dim aLabel() As Label = {Lbl0, Lbl1, Lbl2, Lbl3, Lbl4, Lbl5, Lbl6, Lbl7, Lbl8, Lbl9, Lbl10,
Lbl11, Lbl12, Lbl13, Lbl14, Lbl15, Lbl16, Lbl17, Lbl18, Lbl19, Lbl20, Lbl21, Lbl22, Lbl23,
Lbl24, Lbl25, Lbl26, Lbl27, Lbl28, Lbl29, Lbl30, Lbl31, Lbl32, Lbl33, Lbl34, Lbl35, Lbl36}
Private Sub BtnSpin_Click(sender As Object, e As EventArgs) Handles BtnSpin.Click
'Calls the function from GetRandom() returning a random number
Dim oRandomNumber As New Random_Number_Gen
LblNumber.Text = oRandomNumber.GetRandom()
For i As Integer = 0 To 36
If LblNumber.Text = aLabel(i).Text Then
aLabel(i).BackColor = Color.LightBlue
End If
Next
End Sub
我从For Next循环中的第二行收到异常。