Private Sub Form_Load()
mytext = "0123456789"
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = TestText(KeyAscii, (mytext), True) 'Text1只接受mytext规定以外的字符。
End Sub
Function TestText(KeyIn As Integer, ListString As String, EditBasp As Boolean) As Integer
Dim TestDATList As String '定义限制字符表变量
Dim KeyOut As Integer '返回值变量
If EditBasp = True Then '测试BACKSPACE键是否有效
TestDATList = UCase(ListString)
Else
TestDATList = UCase(ListString) & Chr(8)
End If
If InStr(1, TestDATList, UCase(Chr(KeyIn)), 1) > 0 Then '键值是否在表中
KeyOut = 0 '是则不允许输入
Else
KeyOut = KeyIn '否则允许
End If
TestText = KeyOut '返回结果
End Function