VB 过滤文本框内容

来源:百度知道 编辑:UC知道 时间:2024/04/28 13:46:40
怎样使Text1中只能输入1-9这九个数字?

只能输入数据和退格键

Private Sub Text1_KeyPress(KeyAscii As Integer)

Select Case KeyAscii

Case Asc("0") To Asc("9"), vbKeyBack

Case Else: KeyAscii = 0

End Select

End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode < 48 Or KeyCode > 57 Then
MsgBox "你输入的不是数字"
If Len(Text1.Text) > 0 Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End If
Exit Sub
End If
'.......
'.......
'.......
End Sub

用一个判断语句
dim a
a=text1.text
if a>="a" then
msgbox"输入错误"