口袋社区-Poke The BBS's Archiver

最美我中文 发表于 2007-9-2 13:23

如何让文本框只接受数字

有打错代码的现象,说明也不够清楚,对初学者来说太难,请多用注释~~相关链接
现将改正后的写下来:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= 33 Then '小于33的Ascii代码属于回车空格等操作
If KeyAscii >= 48 And KeyAscii <= 57 Then  '判断是否是0到9的Ascii代码值'
Else
KeyAscii = 0 '把KeyAscii设为0就是取消输入'
MsgBox "请输入数字!"
End If
End If
End Sub
在这里第三行只用keyascii更容易让读者明白。

页: [1]

Powered by Discuz! Archiver 6.1.0F  © 2001-2007 Comsenz Inc.