Have I simple VB program which accumulating via TextBox.Enter fails. Goal is: how fix TextBox.Enter? I do not get MsgBox, indicating that action tree has not been followed.
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
Couldn't you just right a method that does the below? It appears that all your looking is to check to make sure it is an integer that was entered into the textbox and if it is calculate it, otherwise display a messagebox to tell the user to enter a number.
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