怎样编写vb程序 在textbox中输入字母时,弹出提示对话框。急!
发布网友
发布时间:2023-10-02 06:54
我来回答
共2个回答
热心网友
时间:2024-12-03 23:14
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii > Asc("9") Or KeyAscii < Asc("0")) And KeyAscii <> Asc(".") And KeyAscii <> 45 And KeyAscii <> 8 Then KeyAscii = 0
End Sub
'这种方法有缺陷,用户可以输入33..33,建议你使用下面的方法
Private Sub Text1_LostFocus() '文本框失去焦点
If IsNumeric(Text1.Text) = False Then
MsgBox "请输入数字", vbExclamation
ElseIf Trim(Text1.Text) = "" Then
MsgBox "文本框不能为空", vbExclamation
Else
Exit Sub
End If
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
热心网友
时间:2024-12-03 23:15
直接在TEXT的KeyPress事件里进行判断
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then KeyAscii = 0