我使用以下代码在文本框中检查用户输入时出错:
Private Sub txtDeadLoadFactor_TextChanged(sender As Object, e As EventArgs) Handles txtDeadLoadFactor.TextChanged
Dim invalidEntry As Boolean
If IsNumeric(txtDeadLoadFactor.Text) And Not txtDeadLoadFactor.Text = vbNullString Then
If Not txtDeadLoadFactor.Text > 0 Then
invalidEntry = True
End If
Else
invalidEntry = True
End If
If invalidEntry Then
MsgBox("Please only enter numeric data greater than 0 in all fields!", MsgBoxStyle.Critical, "Invalid Input!")
txtDeadLoadFactor.Text = vbNullString
invalidEntry = False
Else
gDeadLoadFactor = txtDeadLoadFactor.Text
End If
End Sub
输入无效时会弹出两次消息框。这是由于将 textbox.text 设置回空字符串所致。我不知道如何防止这种情况发生,如果有人可以帮助清理这个凌乱的代码,我将不胜感激。
谢谢!