Hey e1,

I went out of the way to make my project fool-proof. U can c the pic below, I have 2 input textboxes and 1 output text box. Im trying to get my code to where if you enter a Character i.e. "abc" , then A mSGBox will tell you to enter a valid income amount. The problem Im having is if you enter ne value and/or character, you get a msgbox ne wayz. I would appreciate the help. Peace (files are attached)


11 Years
Discussion Span
Last Post by student101

You need error-trapping for your textboxes, for instance:

If Not IsNumeric(Text1.Text) or Not IsNumeric(Text2.Text) Then
MsgBox ("Invalid Entry")
Exit Sub
End If

rejects non-numeric entries or no entry


If Text1.Text < 10 or Text1.Text > 1000 Then
MsgBox("Entry must be between 10 and 1000")
Text1.Text = ""
Exit Sub
End If

You have to think of every error a user might make, and trap it.


Private Sub cmdCompute_Click()
Dim intNumExemptions As Integer, curIncome As Currency

If lblexemptions.Caption = "" Then
MsgBox "Please enter Exemption", vbExclamation + vbOKOnly, "Enter Tax Exemptions"
Exit Sub
End If

intNumExemptions = CInt(lblexemptions.Caption)
If intNumExemptions <= -1 Then
MsgBox "Please enter Exmption", vbExclamation + vbOKOnly, "Enter Tax Exemptions"
Exit Sub
End If

curIncome = CCur(txtincome.Text)
If curIncome <= 0 Then
MsgBox "Please Enter a Valid Income", vbExclamation + vbOKOnly, "Enter Valid Income"
Exit Sub
End If

txttaxes.Text = Format(curComputeTaxes(intNumExemptions, curIncome), "currency")
End Sub

Compare this with the original code: You were checking the value of the variables before you had assigned a value to them, so they were still 0.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.