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)
這麽壹句