The code requires you to have an error pop up when if its greater than 1, less that 50?
I have to hav开发者_开发知识库e the program display an error if the term the user types is less than 50 or greater than one so anything inbetween is an error. The user must type 50+ or 0 to not get an error. I was almost positive it worked until I looked at the project closer. I get the error when you type any number.
Const strMSG As String = "The term must be less than 1 or greater than 50."
Const strMSG2 As String = "The term must be less than 1 or greater than 50."
txtOwed.Text = FormatCurrency(txtRegistrants.Text * 80)
If txtOwed.Text > 50 Then
txtOwed.Text = txtOwed.Text
Else
MessageBox.Show(strMSG, "Monthly Payment Calculator", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
If txtOwed.Text < 1 Then
txtOwed.Text = txtOwed.Text
Else
MessageBox.Show(strMSG2, "Monthly Payment Calculator", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Change your code to the following:
If val(txtOwed.Text) > 1 and val(txtOwed.Text) < 50 Then
MessageBox.Show(strMSG, "Monthly Payment Calculator", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Note that I solved for your subject line, not your enclosed verbiage and example code
I think this is the easiest for most people to understand:
If not(txtOwed.Text > 50 or txtOwed.text = 0) Then
MessageBox.Show(strMSG, "Monthly Payment Calculator", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
but
not(txtOwed.Text > 50 or txtOwed.text = 0)
is equivalent to
(txtOwed.Text <= 50 and txtOwed.text <> 0)
精彩评论