2012-04-11 14 views
1

アキュムレータ(decTotalCredits)が正常に動作せず、各エントリでゼロにリセットされています。私は125に達するまで、各ユーザーの入力を追加するためにアキュムレータが必要です。通常通り、私はそれが何か小さいと確信しています。すべてのあなたの助けを前にありがとう!アキュムレータがVBで動作しない(Visual Studio 2010)

' 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 

答えて

3

これはあなたのループの外DecTotalCreditsを宣言する必要がループしている場合それは...

  • を再宣言されています。
  • これは、あなたが(右クラスの宣言の下に)あなたのコードの上部にDecTotalCreditsを宣言する必要があるイベントハンドラで、それはハンドラが
+1

はとてもありがとう走るたび再宣言されません。その方法であれば多く!私はクラスレベルにそれを移動し、それは素晴らしい動作します!私もこれを私のメモに入れています! –

関連する問題