
How to cancel a large multiple level procedure from several levels in
I would like to know if there is an elegant way of exiting multiple levels of
sub
procedures.
lets say:
sub1(){
etc...
call sub2()
etc...
Quote:
}
sub2(){
etc...
call sub3()
etc...
Quote:
}
sub3(){
etc...
if condition [ DROP to sub1]
etc...
Quote:
}
There are many many subs & functions which need to act like sub3 (if there was
just one and one caller, the problem would be easy)
[DROP to sub1] is what I don't know how to do:
You cannot say: goto sub1 because goto labels must be in the same procedure.
(It would not be a good thing to do anyway because it would be bad for the call
stack, but you can't do it and pragmatically determine how bad it would be. . .
as far as I know.)
I looked into faking an error condition, so that errors are propigated up
through the caller and all subs say on error goto the end of the sub and exit,
but this
did not work, because error conditions would only last one level. - - - it
still may be possible to do it this way, but I do not know how.
Another approach would be to have some process lurking which allows you to
cancel something it called. (This would be the way of doing it if it was
multithreaded but as far as I know VB is not multithreaded in any way)
A way that would work but that I am trying to avoid would be to exit the sub
normally then right after the call test the same condition and branch if
necessary to the end. I want to limit the number of places I am asking the
same question and this requires asking the same question many many times all
over the place.
None of these approaches worked for me. I would definately appreciate
someone's experience and insight.
David Tollefson