Public Function ValiText(KeyIn As Integer, ValidateString As String, Editable As Boolean) As Integer
Dim ValidateList As String
Dim KeyOut As Integer
If Editable = True Then
ValidateList = UCase(ValidateString) & Chr(8)
Else
ValidateList = UCase(ValidateString)
End If
If InStr(1, ValidateList, UCase(Chr(KeyIn)), 1) > 0 Then
KeyOut = KeyIn
Else
KeyOut = 0
Beep
End If
ValiText = KeyOut
End Function
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = ValiText(KeyAscii, "0123456789", True)
End Sub
ValiText(KeyAscii, 这里是准许输入的字符, True=支持退格)
这个看似复杂,其实是个通用的
Public Function ValiText(KeyIn As Integer, ValidateString As String, Editable As Boolean) As Integer
这个是个函数,你复制到你的程序里就可以了
然后在你需要限制输入内容 的文本框的 KeyPress 事件里调用这个函数 就OK啦~
调用代码就
KeyAscii = ValiText(KeyAscii, "0123456789", True)
这么一句
温馨提示:答案为网友推荐,仅供参考