VB只可以输入数字,否则弹出提示

来源:百度知道 编辑:UC知道 时间:2024/09/24 11:26:51
Command后
如果发现TEXT不是数字则弹出提示
否则 则继续下一代码

Private Sub Command1_Click()
If IsNumeric(Text1) = False Then
MsgBox "不是数字!"
Exit Sub
End If
'继续
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < Asc(0) Or KeyAscii > Asc(9) Then
KeyAscii = 0
MsgBox "请输入数字"
End If
End Sub