Reputation: 99
I have 2 subs that look like this: How can i stop my "main" sub if my statement is true in the sub i just called?
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
Upvotes: 1
Views: 703
Reputation: 82474
You can't do it if Run()
is a Sub. You need your Run()
as a Function. return a Boolean indicating if you want to stop main
, and call in inside an If
:
Public Function run() As Boolean
If ProgressBar1.Value = 100 Then
Return True
End If
' some more code if needed
Return False
End Function
Then call it in your main sub like this:
Public Sub main()
' some main code here
If Run() Then
Return
End If
' The rest of main code here
End Sub
Upvotes: 2