我是否通过TextBox.Enter累积的简单VB程序失败。目标是:如何修复TextBox.Enter?我没有得到MsgBox,表明没有遵循动作树。
Option Explicit On
Public Class MainForm
Public decexpenses, decincome As Decimal
Public dectotalexpenses As Decimal = 0
Public dectotalincome As Decimal = 0
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MsgBox("Use Enter key to enter values.")
End Sub
Private Sub expensesTextBox_Enter(sender As Object, e As EventArgs) Handles expensesTextBox.Enter
Do Until expensesTextBox.Text = String.Empty
Dim expenses = expensesTextBox.Text
MsgBox(expenses) ' i dont get a msgbox for this indicating this value is null
Do Until IsNumeric(expenses)
MsgBox("Please enter numeric value for expenses.")
Loop
decexpenses = CDec(expenses)
dectotalexpenses = decexpenses + dectotalexpenses
Loop
End Sub
Private Sub incomeTextBox_Enter(sender As Object, e As EventArgs) Handles incomeTextBox.Enter
Do Until incomeTextBox.Text = String.Empty
Dim income = incomeTextBox.Text
Do Until IsNumeric(income)
MsgBox("Please enter numeric value for income.")
Loop
decincome = CDec(income)
dectotalincome = decincome + dectotalexpenses
Loop
End Sub
End Class
答案 0 :(得分:1)
难道你不能正确地执行下面的方法吗?看起来你要检查的是确保它是一个输入到文本框中的整数,如果是计算它,否则显示一个消息框告诉用户输入一个数字。
Private Sub expensesTextBox_Enter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles expensesTextBox.KeyPress
Dim dectotalexpenses As Decimal = 0
Dim dectotalincome As Decimal = 0
Dim income As String = expensesTextBox.Text
If Keys.E + Keys.Enter Then
If IsNumeric(income) = True Then
dectotalincome = income + dectotalexpenses
Else
MessageBox.Show("Please Enter A Number")
End If
End If
End Sub