SH********@aol.com wrote:
If I'm in, say, a 3rd level sub and want to exit, not only the sub but
the entire procedure, without a GoTo, can this be done without using
switches?
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Huh? I'm assuming you mean that you have a subroutine that has been
called like this:
Sub 1 calls-> Sub 2 calls-> Sub 3
And you want to exit Sub 3 back to Sub 1 without doing anything in Sub
2. There is no way to go directly back to Sub 1. You have to Exit Sub
3 w/ some kinda of flag set that indicates to Sub 2 that Sub 3 is ending
in a defined state. Sub 2 checks that flag and if it means something
like "stop all procedures in Sub 2" then Sub 2 immediately Exits back to
Sub 1. Sub 2 can set another flag, or just return the same flag that
Sub 3 set, that "tells" Sub 1 that Sub 2 stopped because of the flag
received from Sub 3.
What I do is set up error traps in Sub 1 and no error traps in Sub 2 &
Sub 3. Then if something happens in Sub 3 that makes me want to return
to Sub 1 w/o any interference by the intervening Subs I use Err.Raise in
Sub 3. This will cause a cascade back thru all intervening Subs until
it hits a Sub that has an error trap. Then that Sub does whatever is
necessary when that user-defined error appears. E.g.:
Private Sub Sub1()
On Error GoTo err_
' call Subs
Sub2
exit_:
Exit Sub
err_:
If Err.Number = vbObjectErr+513 Then
' Handle the Sub 3 state exit code
Else
' usual error handling code
End If
End Sub
Private Sub Sub2()
' call Sub 3
Sub3
End Sub
Private Sub Sub3()
' does whatever ....
' Here it checks to see if it needs to jump back to Sub 1
If <some condition> = True Then
Err.Raise vbObjectError + 513 'the number indicates the Sub's state
End If
End Sub
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBQtf17IechKqOuFEgEQLbogCfRpyiPJiLvRHaT1Q/u16m11QSAS0AnRhl
a+fmC+DM8Kq8qJTrOPGCjBvc
=qR/v
-----END PGP SIGNATURE-----