我有2个看起来像这样的潜艇: 如果我的声明在我刚刚调用的子语句中为真,我怎么能停止我的“主”子?
Public Sub main()
call run()
more code....
End Sub
Public Sub run()
If ProgressBar1.Value = 100 Then
(i want to stop the code running if this statement is true, it shall not continue in my main sub.)
End If
End Sub
答案 0 :(得分:2)
如果Run()
是Sub,则无法执行此操作。您需要Run()
作为函数。返回一个布尔值,指示您是否要停止main
,并在If
内调用:
Public Function run() As Boolean
If ProgressBar1.Value = 100 Then
Return True
End If
' some more code if needed
Return False
End Function
然后在你的主要子中调用它:
Public Sub main()
' some main code here
If Run() Then
Return
End If
' The rest of main code here
End Sub