Stopping other subs from running while in a Sub
Is there a way to stop other subs from running while in a separate sub.
for instance say your in the sub CreateNumber()
and the subs are setup like
CreateNumber()
AddNumber() DeleteNumber()Is there a way to be in CreateNumber() and call a function to stop AddNumber from running after cre开发者_如何学CaetNumber() is finished? i just want my program to sit there to wait for an event to happen.
Just do this:
CreateNumber()
WaitForSomeEventToHappen()
AddNumber()
DeleteNumber()
If you're not using threads, then these Subs will simply be called in sequence, so you don't have to do anything "clever".
If you want CreateNumber to be able to control whether or not AddNumber() will be executed, then you can make it into a Function and return a result - e.g.
Public Function CreateNumber() As Boolean
...create the number...
if (numberCreatedOk)
return(True);
return(False);
End Function
Then call it like this:
if (CreateNumber()) then
AddNumber()
DeleteNumber()
end if
In this way, you only call the remaining Subs if CreateNumber() returned True.
精彩评论