双信息显示 - VBA
Double message display - VBA
在下面的代码中,当输入的值不正确时会显示一条错误消息。由于字段为空而删除错误值时再次显示错误消息。我怎样才能再次停止显示消息?
Private Sub textbox1_Change()
If TextBox1 < 1 Or TextBox1 > 31 Then
Beep
MsgBox "Please enter numbers between 1 and 31."
TextBox1= ""
TextBox1.SetFocus
End If
End Sub
Private Sub textbox1_Change()
Static self_protect As Boolean
If self_protect Then Exit Sub
If TextBox1 < 1 Or TextBox1 > 31 Then
Beep
MsgBox "Please enter numbers between 1 and 31."
self_protect = True
TextBox1 = ""
TextBox1.SetFocus
self_protect = False
End If
End Sub
Private Sub textbox1_Change()
Select Case True
Case Len(TextBox1.Text) = 0
Case TextBox1.Value < 1 Or TextBox1.Value > 31
Beep
MsgBox "Please enter numbers between 1 and 31."
TextBox1 = ""
TextBox1.SetFocus
End Select
End Sub
或
Private Sub textbox1_Change()
If Len(TextBox1.Text) = 0 Then Exit Sub
If TextBox1 < 1 Or TextBox1 > 31 Then
Beep
MsgBox "Please enter numbers between 1 and 31."
TextBox1 = ""
TextBox1.SetFocus
End If
End Sub
在下面的代码中,当输入的值不正确时会显示一条错误消息。由于字段为空而删除错误值时再次显示错误消息。我怎样才能再次停止显示消息?
Private Sub textbox1_Change()
If TextBox1 < 1 Or TextBox1 > 31 Then
Beep
MsgBox "Please enter numbers between 1 and 31."
TextBox1= ""
TextBox1.SetFocus
End If
End Sub
Private Sub textbox1_Change()
Static self_protect As Boolean
If self_protect Then Exit Sub
If TextBox1 < 1 Or TextBox1 > 31 Then
Beep
MsgBox "Please enter numbers between 1 and 31."
self_protect = True
TextBox1 = ""
TextBox1.SetFocus
self_protect = False
End If
End Sub
Private Sub textbox1_Change()
Select Case True
Case Len(TextBox1.Text) = 0
Case TextBox1.Value < 1 Or TextBox1.Value > 31
Beep
MsgBox "Please enter numbers between 1 and 31."
TextBox1 = ""
TextBox1.SetFocus
End Select
End Sub
或
Private Sub textbox1_Change()
If Len(TextBox1.Text) = 0 Then Exit Sub
If TextBox1 < 1 Or TextBox1 > 31 Then
Beep
MsgBox "Please enter numbers between 1 and 31."
TextBox1 = ""
TextBox1.SetFocus
End If
End Sub