vb LostFocus语句 如何让text中不输入的时候 不执行 还有 怎么用LostFocus去掉非数字 和负数 谢谢大家

来源:百度知道 编辑:UC知道 时间:2024/06/14 20:11:16
(我编的程序不在text中输入也报错)
并限定在128~4096

在有效代码外面套一个if text1.text<> "" then 。。。。end if就可以了吧

Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then KeyAscii = 0
'过滤掉 0-9 退格键以外的其他字符
End Sub

Private Sub Text1_LostFocus()
Text1.Text = Trim(Text1.Text)
If IsNumeric(Text1.Text) Then
If Val(Text1.Text) >= 128 And Val(Text1.Text) <= 4096 Then
'你的处理代码
Exit Sub
End If
End If
MsgBox "请输入介于128到4096的数字!"
Text1.SetFocus
'Text1.Text =""
End Sub