TextBox 中接受某些特定字符,例如 /'@#$%/",简单的写法

来源:互联网 发布:java公司客户管理系统 编辑:程序博客网 时间:2024/05/21 11:21
    TextBox 中接受某些特定字符,例如 /'@#$%/",简单的写法   方法1:  可以使用 IF 或 Select Case 一个个判断, 但如果不接受的字符多时, 较麻烦!  
方法2:  将要剔除的字符统统放在一个字串中,只要一个 IF 判断即可 !! 如下: 
Private Sub Text1_KeyPress(KeyAscii As Integer) 
Dim sTemplate As String 
sTemplate = "!@#$%^&*()_+-=" '用来存放不接受的字符 
If InStr(1, sTemplate, Chr(KeyAscii)) > 0 Then 
KeyAscii = 0 
End If 
End Sub
原创粉丝点击