0

我有一种感觉,我又把事情复杂化了。下面的脚本是我正在尝试做的基础知识。我遇到的问题是msgboxes。

基本上,我需要一个用于条件 B 失败(并退出)的 msgbox 和一个用于成功完成循环的 msgbox。所以,他们每个人都需要遵循不同的条件,但我不知道该怎么做?

For i = 1 To Val(days)
If hasrun = False Then
    If condition A <> 0 Then do nothing
        ElseIf condition A = 0 Then
            Do this...
    End If
If condition B <> 0 Then
    Exit For
ElseIf condition B  = 0 Then
    Do that…
End If
 Do this other code...   
hasrun = True
Next i
    MsgBox "Script exited because condition B already existed"

    MsgBox "Script finished successfully."
End if
4

1 回答 1

2

您可以只记录使用标志变量发现问题的事实:

Dim blnBFail As Boolean     
For i = 1 To Val(days)
If hasrun = False Then
    If condition A <> 0 Then do nothing
        ElseIf condition A = 0 Then
            Do this...
    End If
If condition B <> 0 Then
    blnBFail = True
    Exit For
ElseIf condition B  = 0 Then
    Do that…
End If
 Do this other code...   
hasrun = True
Next i

If blnBFail then
    MsgBox "Script exited because condition B already existed"
Else
    MsgBox "Script finished successfully."
EndIf
End if
于 2013-03-27T18:02:21.203 回答