How to cancel a large multiple level procedure from several levels in 
Author Message
 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



Sat, 17 Feb 2001 03:00:00 GMT  
 How to cancel a large multiple level procedure from several levels in
To make an item jump from one sub to another you would simply tell it to call that
sub from within your IF statement.

EX.  (You had this)

sub3(){
    etc...
    if condition [ DROP to sub1]
    etc...

Quote:
}

Insteade of [DROP to sub1] use this:

sub3(){
    etc...
    if condition then
        sub1()
    end if
    etc...

Quote:
}

My EX.

If X = 5 then
    Sub1()
End if

You can also go from one sub to another by simple stating the name of the sub.

EX.  If you want to automatically jump back to sub1 after executing sub3, you could
say:

sub()

.....
code
......
code
.......
sub1()

end sub
--
_____________________________________________________________

Cringer's Index Page
http://www.west.ga.net/~eternia/index.html

Richardson Karate-Kobudo Dojo
http://www.west.ga.net/~eternia/Dojo/dojo.html
_____________________________________________________________



Sat, 17 Feb 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. canceling through multiple levels of sub procedures in VB

2. dim at procedure level or module level

3. Problem in Share-Level to User-Level, VB6,Jet4

4. Remote Data Objects in combination with level 1 compliance level

5. VB6 - Capture KeyUp at Form Level - Not FileListBox Control Level

6. Module Level Versus Subroutine Level

7. Paths -- Creating File Path with several levels -- VBScript

8. several levels of quotes

9. Locking on procedure level

10. Procedure Level Locking

11. Multi-Level Procedure/Coding

12. ??Calling Sub-Menu_Click from Module Level Procedures???

 

 
Powered by phpBB® Forum Software