我有一个代码,我将在其中输入付款,如果我输入的payment
小于total
金额,它将显示一个消息框。出于测试目的,我有意输入了小于total
数量的payment
,但在第二次删除文本框中的数字并输入正确数量时,消息框仍显示
If (paymentbox.Text < total) Then
MessageBox.Show("Please enter sufficient amount of payment")
Else
changebox.Text = paymentbox.Text - total
totalpricebox.Text = total.ToString("c")
End If
顺便说一句,这段代码在我的ordernbtn_click事件中,我想刷新一个表单,因为我不能同时执行Me.Close()
和Me.Show()
,但任何建议都会有所帮助。
只需在检查前解析Paymentbox.Text
即可:
Dim payment As Integer
If (Integer.TryParse(paymentbox.Text, payment)) Then
If (payment < total) Then
MessageBox.Show("Please enter sufficient amount of payment")
Else
'Do stuff
End If
Else
MessageBox.Show("Please enter a valid amount of payment")
End If
Integer.TrayParse
将检查输入文本是否有效,如果有效则返回true
,并将使用有效的integer
更改支付变量。