如果myValue = 0 or myValue > nbRisk
我必须循环留言
当myValue > 0 and <= nbRisk
我继续
例如,如果我把myValue = 5,它再循环,当我放
myValue = 10或11 ..它不循环
有什么想法吗?
这是我的代码
Do While myValue = 0 or myValue > nbRisques
myValue = InputBox (Enter number of risk");
loop
For i=1 to myValue
答案 0 :(得分:1)
尝试以下解决方法:
' define myValue as Long
Dim myValue As Long
Do While myValue = 0 Or myValue > nbRisques
On Error GoTo InputBox_Err_Handler
myValue = InputBox("Enter level of Risk to assess")
InputBox_Err_Handler:
If Err.Number <> 0 Then
MsgBox "Error, only Number format is allowed"
End If
Loop
答案 1 :(得分:0)
首先,将myValue
更改为变体。
然后您的代码可以更改为
Do While myValue = 0 Or myValue > nbrisques
myValue = InputBox("Enter level of Risk to assess")
If IsNumeric(myValue) Then
myValue = CInt(myValue) ' Using CInt on the assumption that you want an Integer
Else
myValue = 0
End If
Loop