Vb.net 我的累加器和计算在VB 2010中不起作用

Vb.net 我的累加器和计算在VB 2010中不起作用,vb.net,Vb.net,好的,我的累加器现在正以合计的形式正确地添加和显示。然而,我的if中有点不对劲。。。然后声明,它不会在达到125后将其扔到第二级。我可以点击125,我需要输入一个条目来启用我的按钮。感谢您的帮助 *编辑以显示随Do While循环更新的内容。现在导致我的输入错误msgbox出现问题* decTotalCredits

好的,我的累加器现在正以合计的形式正确地添加和显示。然而,我的if中有点不对劲。。。然后声明,它不会在达到125后将其扔到第二级。我可以点击125,我需要输入一个条目来启用我的按钮。感谢您的帮助

*编辑以显示随Do While循环更新的内容。现在导致我的输入错误msgbox出现问题*

decTotalCredits<125时执行 如果是数字(txtCredit.Text),则 '此语句将把输入的字符串转换为十进制并建立 '输入作为decCredit变量 decredit=Convert.ToDecimal(txtCredit.Text) “本案例陈述旨在验证硬币的正确面额是否正确 “正在进入机器。 选择案例信用 案例5、10、25、100 '此行将新输入的信用添加到 “现有总数 decTotalCredits+=decCredit lblTotal.Text=Convert.ToString(decTotalCredits) lblTotal.Visible=True '重置贷方金额的文本输入框 txtCredit.Clear() txtCredit.Focus() 其他情况 '如果输入的信用证不符合以下条件,则会显示此消息: "与普通硬币一致" MsgBox(“请输入有效的硬币金额”,“输入的金额无效”) 结束选择 其他的 '当用户输入非数字条目时,将出现此消息 MsgBox(“请输入有效的硬币金额”,“输入错误”) 如果结束 环 '循环应在积分达到125并激活此代码时完成 '一旦达到积分,进行选择的提示即可见。 lblMakeSelection.Visible=True '一旦达到积分,选择按钮将启用。 btnDietPepsi.Enabled=True btnPepsi.Enabled=True btnSierraMist.Enabled=True btnLemonade.Enabled=True btndrpeaper.Enabled=True btnWater.Enabled=True 端接头
根据您给我们的代码,它将进入循环,添加到总数中,擦除txtCredit文本框,再次启动循环,然后显示错误消息框,因为txtCredit不再是数字


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

在添加当前信用之前,您正在检查总信用。谢谢。。。我已将原始IF语句更改为Do While循环。。。现在给我msgbox的错误。。。它们会弹出,不允许输入新数据。。。是“输入错误”给了我麻烦,为什么它在循环中?这是保证不工作,现在…可能的重复它不是一个重复,因为现在我的累加器计算正确。然而,它并没有踢到if语句的第二级,直到我在击125后输入另一个条目。。。所以我不确定。。。我正在努力。。。谢谢你的帮助。这是我上的第一堂VB课,所以我是个十足的傻瓜…我确实回到了if。。。然后是语句,一个表示<125,一个表示>=125。这解决了我的问题,现在我的程序正在运行!谢谢
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