1
我有一個簡單的VB程序,它通過TextBox.Enter累積失敗。目標是:如何修復TextBox.Enter?我沒有收到MsgBox,表明沒有遵循行動樹。VB textbox.enter給出空值(累加器)
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
在大多數情況下,當用戶去/激活/進入文本框的內容是空的,所以外面的'Do Until'條件已經滿足,什麼也沒有發生。好東西,因爲內部的'Do Until'是MsgBoxes的無限風雪 – Plutonix
你是什麼意思? –
您在輸入任何內容之前正在進行驗證。在離開事件中驗證或使用驗證事件。你不能在事件中使用這樣的循環 - 你必須退出事件,以便他們可以輸入/更正輸入 – Plutonix