VB中的inputbox中的文本如果只限定输入数字,要怎么写代码呀?各位帮帮我吧

来源:百度知道 编辑:UC知道 时间:2024/05/25 13:25:16

简单点的:
mm = InputBox("请输入数量:", "请输入")
If IsNumeric(mm) <> True Then
mx = MsgBox("必须是数字!)
Endif
或者用ASCII判断
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub
-----------------------------
完整点的,(包括小数点,分数等等):
Private Sub text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Asc("-") '允许负数
If text1.SelStart = 0 Then
If Left(text1.Text, 1) = "-" Then
KeyAscii = 0

End If
Else
KeyAscii = 0