编程语言

img foko_zl

限制文本框的输入(只输入数字)

发表于2004/10/18 11:07:00  449人阅读

文本框防止非法字符输入:

只输入整数:
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii   
Case Asc("0") To Asc("9"), vbKeyBack
        'nop
Case Else
        KeyAscii = 0
End Select
End Sub

只输入小数:

Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Asc("0") To Asc("9"), vbKeyBack
 'nop

case Asc(".")'允许一个小数点
 If InStr(1, Text1.Text, ".") > 0 Then KeyAscii = 0

Case Else
        KeyAscii = 0

End Select
End Sub

阅读全文
0 0

相关文章推荐

img
取 消
img