我的累加器 (decTotalCredits) 工作不正常,每次输入时都重置为零。我需要累加器添加每个用户输入,直到达到 125。通常情况下,我确信它很小。提前感谢您的所有帮助!
' Declaring variable for Credit Entered by User
Dim decCredit As Decimal = CDec(txtCredit.Text)
' Declaring the accumulator
Dim decTotalCredits As Decimal
If IsNumeric(txtCredit.Text) Then
decCredit = Convert.ToDecimal(txtCredit.Text)
Select Case decCredit
Case Is = 5
Case Is = 10
Case Is = 25
Case Is = 100
Case Else
MsgBox("Please enter a valid coin amount", , "Invalid Amount Entered")
End Select
If decTotalCredits < 125 Then
decTotalCredits += decCredit
lblTotal.Text = CStr(decTotalCredits)
lblTotal.Visible = True
txtCredit.Clear()
txtCredit.Focus()
Else
' Once the credits are reached the prompt to make selection is visible.
lblMakeSelection.Visible = True
' Once the credits are reached, the buttons for selection become enabled.
btnDietPepsi.Enabled = True
btnPepsi.Enabled = True
btnSierraMist.Enabled = True
btnLemonade.Enabled = True
btnDrPepper.Enabled = True
btnWater.Enabled = True
End If
Else
MsgBox("Please enter a valid Coin amount", , "Input Error")
End If