如果用户输入的术语小于50或大于1,则必须让程序显示错误,因此中间的任何内容都是错误。用户必须键入50+或0才能收到错误。我几乎是肯定的,直到我仔细看了一下这个项目。输入任何数字时都会收到错误。
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
答案 0 :(得分:2)
将您的代码更改为以下内容:
If val(txtOwed.Text) > 1 and val(txtOwed.Text) < 50 Then
MessageBox.Show(strMSG, "Monthly Payment Calculator", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
请注意,我解决了您的主题,而不是您附上的措辞和示例代码
答案 1 :(得分:0)
我认为这对大多数人来说最容易理解:
If not(txtOwed.Text > 50 or txtOwed.text = 0) Then
MessageBox.Show(strMSG, "Monthly Payment Calculator", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
但
not(txtOwed.Text > 50 or txtOwed.text = 0)
相当于
(txtOwed.Text <= 50 and txtOwed.text <> 0)