我想在一个文本框中限制输入数字和英文,但下面的程序对输入“'”“/”等几个标点没有限制,请知道的高手指出错误,代码如下:
Private Sub Text2_KeyPress(KeyAscii As Integer) If (KeyAscii < 48 And KeyAscii > 122) Or (KeyAscii < 65 And KeyAscii > 57) Or (KeyAscii < 97 And KeyAscii > 90) Then MsgBox "请输入正确的数据!", 48, "注意" KeyAscii = 0 End If End Sub
Private Sub Text2_Change() key = Asc(Right(Me.Text2.Text, 1)) If (key < 48 And key > 122) Or (key < 65 And key > 57) Or (key < 97 And key > 90) Then MsgBox "请输入正确的数据!", 48, "注意" 'Me.Text2.Text = Left(Me.Text2.Text, Len(Me.Text2.Text) - 1) End If End Sub
If Not ((KeyAscii < Asc("z") And KeyAscii > Asc("a")) Or (KeyAscii < Asc("Z") And KeyAscii > Asc("A")) Or (KeyAscii < Asc("9") And KeyAscii > Asc("0"))) Then