2012-04-13 99 views
0

好的,所以我的累加器现在可以在表单中正确添加和显示。然而,在我的if ... then语句中出现了一些错误,并且在达到125后没有将它扔到第二级。我可以打125,我需要输入一个条目才能启用我的按钮。任何帮助表示赞赏!我的累加器和计算不能在VB 2010中工作

* 编辑显示用Do While Loop进行更新。现在造成的问题与我输入错误的msgbox ... *

do while decTotalCredits < 125 
     If IsNumeric(txtCredit.Text) Then 
      ' This statement will convert the string entered to decimal and establish the 
      ' input as the decCredit Variable 
      decCredit = Convert.ToDecimal(txtCredit.Text) 
      ' This Case Statement is to verify that the correct denominations of coins are 
      ' being entered in the machine. 
      Select Case decCredit 
       Case 5, 10, 25, 100 
        ' This line adds the newly entered credit to the 
        ' exsisting total 
        decTotalCredits += decCredit 
        lblTotal.Text = Convert.ToString(decTotalCredits) 
        lblTotal.Visible = True 
        ' reset the text input box for the credit amount 
        txtCredit.Clear() 
        txtCredit.Focus() 
       Case Else 
        ' This message will appear if a Credit is entered that does not 
        ' conform to normal coins 
        MsgBox("Please enter a valid coin amount", , "Invalid Amount Entered") 
      End Select 
     Else 
      ' This message will occur when a user inputs a non-numeric entry 
      MsgBox("Please enter a valid Coin amount", , "Input Error") 
     End If 
    Loop 

    ' Loop should complete when credits hit 125 and activate this code 
    ' 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 Sub 
+1

在添加当前信用额度之前,您正在检查总信用额度。 – Ryan 2012-04-13 00:17:20

+0

谢谢......我已经将原来的IF语句更改为Do While Loop ...现在给我的msgbox发出错误......他们弹出并且不允许输入新数据......这是“INPUT错误“,这给我带来麻烦 – 2012-04-13 00:33:48

+0

为什么它在一个循环?这是保证现在不工作... – Ryan 2012-04-13 00:46:40

回答

1

从您给予我们的代码,它将进入循环,增加总擦拭txtCredit文本框,再然后启动循环显示错误消息框,因为txtCredit不再是数字。

假设逻辑位于按钮单击或TextBox验证例程中,建议您删除循环并在启用按钮之前添加“If decTotalCredit> = 125 Then”语句。

+0

我没有回到if ... then语句,一个为<125和一个为> = 125.这解决了我的问题,现在我的程序正在运行!谢谢! – 2012-04-13 17:12:21