vb中想让一个文本框只能输入数字
下面代码可实现文本框只能输入数字:
Option Explicit
Private Sub Form_Load()
Text1= ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii Asc("9") Then
KeyAscii = 0 '取消字符。
Beep '发出错误信号。
End If
End Sub
如需输入小数点,则代码如下:
Private Sub Form_Load()
Text1 = ""
End Sub
Private Sub text1_KeyPres...全部
下面代码可实现文本框只能输入数字:
Option Explicit
Private Sub Form_Load()
Text1= ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii Asc("9") Then
KeyAscii = 0 '取消字符。
Beep '发出错误信号。
End If
End Sub
如需输入小数点,则代码如下:
Private Sub Form_Load()
Text1 = ""
End Sub
Private Sub text1_KeyPress(KeyAscii As Integer)
If KeyAscii Asc("。
") Or KeyAscii > Asc("9") And KeyAscii <> Asc("。") Or KeyAscii = Asc("/") Then
KeyAscii = 0 '取消字符。
End If
End Sub
。收起