1\inputbox 按取消后,返回的结果是空值.以此判断.
2\ 无法直接限制inputbox 里的输入字符,只能判断它的返回值来确定
可以使用循环来
如:
Private Sub Command1_Click()
Dim i As Single
Dim j As String
Do
j = InputBox("请输入一个正整数:", "标题")
j = Trim(j)
If j = "" Then
MsgBox "空值或取消"
ElseIf Not IsNumeric(j) Then
MsgBox "非数字"
Else
i = CSng(j)
If i <> Int(i) Then
MsgBox "有小数"
ElseIf i < 0 Then
MsgBox "非正数"
Else
Exit Do
End If
End If
Loop
MsgBox i
End Sub