VB问题,

来源:百度知道 编辑:UC知道 时间:2024/06/14 05:50:54
用KeyAscii来完成,只让字母键有用,其它的不能用,如何做?

Private Sub Text1_KeyPress(KeyAscii As Integer)

If (KeyAscii <= 122 And KeyAscii >= 97) Or (KeyAscii <= 90 And KeyAscii >= 65) Then
Else
KeyAscii = ""
End If

比如说你要在 Text1 里面输入 的只能是字母,而其他的数字和符号不能输入则可以用下面的代码:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not ((KeyAscii >= 97 And KeyAscii <= 122) Or Not (KeyAscii >= 65 And KeyAscii <= 90) Or KeyAscii = vbKeyReturn Or KeyAscii = vbKeyBack) Then KeyAscii = 0
End Sub

private sub text1_keypress(keyascii as integer)
if keyascii >= asc("a") and keyascii <=asc("z") _ '小写字母
or keyascii >= asc("A") and keyascii <= asc("Z") _ '大写字母
or keyascii =8 then '退格
Else
keyascii=0
end if
end sub