我正在试图获取我编写的这些代码来简单地添加下注金额,运行循环并添加下注金额等等。如果你丢失然后将其添加到损失标签,循环并最终保持跟踪您下注的次数。
你能帮我理顺吗?
Option Strict Off
Public Class RaceSeries
' declare variables
Const intMAX_INDEX As Integer = 0
Dim intBetValue As String
Dim intBetValue2 As String
Dim intRacerNum As String
Dim Count As Integer
Dim intNum As Integer
Dim rand As New Random
Dim decGuess As Decimal
Dim intBet As Integer
Dim blnFlag1 As Boolean
Dim blnFlag2 As Boolean
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnBack.Click
Me.Close()
End Sub
Private Sub btnBetOnRace_Click(sender As Object, e As EventArgs) Handles btnBetOnRace.Click
'activate sound clip
My.Computer.Audio.Play(My.Resources.FlyBy,
AudioPlayMode.Background)
'verify Input() Is numeric and get bet amount
intBetValue = InputBox("How much would you like to bet?")
If IsNumeric(intBetValue) Then
MsgBox("You are betting " & CInt(intBetValue).ToString("C"))
blnFlag1 = True
Else
MsgBox("You provided an invalid value")
blnFlag1 = False
End If
End Sub
Private Sub btnPick_Click(sender As Object, e As EventArgs) Handles btnPick.Click
' verify input and get racer number
intRacerNum = InputBox("Choose the racer you would like to bet on")
If IsNumeric(intRacerNum) And intRacerNum < 7 And intRacerNum >= 1 Then
MsgBox("You have picked racer # " & CInt(intRacerNum).ToString)
blnFlag2 = True
Else
MsgBox("Choose a racer # 1-6")
blnFlag2 = False
End If
End Sub
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
If blnFlag1 And blnFlag2 = True Then
Do While Count <= intMAX_INDEX
Count += 1
'get a random integer and assign it to intnum
intNum = rand.Next(6)
If intNum <> intRacerNum Then
intBetValue = intBetValue * Count
lblLost.Text = intBetValue
MsgBox("Your Rider Lost The Race")
lblDailyBets.Text = Count
Exit Do
ElseIf intNum = intRacerNum Then
intBetValue = intBetValue * Count
lblLost.Text = intBetValue
lblWinnings.Text = intBetValue
MsgBox("Congratulations, Your Rider Won The Race")
End If
lblDailyBets.Text = Count
Loop
Else
MsgBox("You must enter a bet and pick a racer")
End If
End Sub
End Class
答案 0 :(得分:1)
您的问题似乎出现在btnStart_Click()
事件中。
变量intMAX_INDEX
似乎没有设置。如果此变量设置为大于零,则每次按下开始按钮时都会循环多个比赛(这可能是您想要的,或者不是。)
此外,您将通过计数乘以赢额和损失金额。你是想让每场比赛都比前一场比赛更大吗?如果没有,您不应该将您的下注金额乘以Count。
此外,您在每场比赛后都会覆盖您的输赢标签值,这会使之前比赛的奖金/损失无效。如果你想保持一个总计,你需要加上现有的奖金/亏损金额,如下:
lblWinnings.Text = CInt(lblWinnings.Text) + intBetValue
最后,我非常确定rand.Next(6)
会生成0到5之间的数字,但永远不会返回数字6.因为您的用户选择1到6之间的数字,所以应该设置intNum = rand.Next(6)+1.