限制键盘的录入,
Private Sub txthandset_KeyPress(KeyAscii As Integer)
KeyAscii = isValidText(KeyAscii, "-0123456789.", True)
End Sub
Public Function isValidText(KeyIn As Integer, ValidateString As String, Editable As Boolean) As Integer 'dml add
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
isValidText = KeyOut
End Function
博客展示了限制键盘录入的代码。通过 Private Sub 过程调用 isValidText 函数,该函数可根据传入的验证字符串和可编辑状态,判断输入字符是否合法,合法则返回原字符,不合法则返回 0 并发出提示音。
57

被折叠的 条评论
为什么被折叠?



