下面这段vb代码为什么出两次提示信息
来源:百度知道 编辑:UC知道 时间:2024/06/21 23:48:17
Private Sub Text1_Change()
If Not IsNumeric(Text1.Text) & "" Then
Dim k
k = MsgBox("请按要求输入!", vbInformation, "提示")
Text1.Text = ""
Text1.SetFocus
End If
Private Sub Text1_Change()
If IsNumeric(Text1.Text) Or Text1.Text = "" Then
Exit Sub
Else
Dim k
k = MsgBox("请按要求输入!", vbInformation, "提示")
Text1.Text = ""
Text1.SetFocus
End If
End Sub
这样就没问题了
If Not IsNumeric(Text1.Text) & "" Then
Dim k
k = MsgBox("请按要求输入!", vbInformation, "提示")
Text1.Text = ""
Text1.SetFocus
End If
Private Sub Text1_Change()
If IsNumeric(Text1.Text) Or Text1.Text = "" Then
Exit Sub
Else
Dim k
k = MsgBox("请按要求输入!", vbInformation, "提示")
Text1.Text = ""
Text1.SetFocus
End If
End Sub
这样就没问题了
代码中 Text1.Text = "" 引起 change事件 所以就出现2次
你把text1.setfocus去掉大概就没有了
setfocus和change有重合的部分
====================================
哈?那样该没问题了?
貌似违背了你的本意了吧 if 的条件反了
如果翻译过来的话:“如果text1.text是数字或为空,则结束sub”
无语………………
条件改一下就对了。不过你的问题依旧
我这里只出现一次提示
Text1.SetFocus