即使我第二次输入了正确的输入,我的消息框警报仍在继续发生

  • 本文关键字:继续 消息 第二次 vb.net
  • 更新时间 :
  • 英文 :


我有一个代码,我将在其中输入付款,如果我输入的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更改支付变量。

最新更新