|
-
Feb 28th, 2002, 10:47 AM
#1
Thread Starter
New Member
Exiting outer subs
I have a sub, which calls a sub, which calls a sub (i.e. 3 levels). If an error occurs in the level 3 sub, the error handler exits the inside/level 3 sub, but the rest of the program continues....I want the entire thing to shut down, rather than just exiting the inside/level 3 sub, because the nature of the error requires the user to fix an excel file causing the error and run the entire thing again.
Is there a way for an inner sub to send a message to all outer subs to shut down after an error occurs in the inner sub, rather than continue running the outer sub(s)?
-
Feb 28th, 2002, 10:50 AM
#2
Frenzied Member
Do boolean functions instead and return false if an error occurs.
From sub 2
If Function3 = false then
MsgBox "Error occured in Function 3"
end if
-
Feb 28th, 2002, 10:50 AM
#3
create a public variable that the middle sub sets then check its value after the sub is called
like if the error happens
blnError = True
then after the code calling the sub
If blnError = True Then
Exit Sub
End If
set it to false later to make sure the value is reset for when it goes through those subs again
-
Feb 28th, 2002, 10:50 AM
#4
Bouncy Member
yup, dead easy.
create an error handler in Sub1,
and dont have an error handler in sub2 or sub3,
then sub1 will handle it...
error-handling is handles heiracally (i think that's the right word!)
-
Feb 28th, 2002, 10:51 AM
#5
Hyperactive Member
Try using a global Boolean variable set it to True
If an error occurs set it to false
Then in each sub that calls another sub next line check the Bool if false exit this sub and so on.
-
Feb 28th, 2002, 10:52 AM
#6
Hyperactive Member
Snap
Snap
Snap
-
Feb 28th, 2002, 10:53 AM
#7
Smack
Smack
Smack.
you gotta be faster then that Glen
-
Feb 28th, 2002, 10:54 AM
#8
Declare a boolean as true or false in the level 2 and 3 subs before exiting them and check them in the level 1 and 2 subs....
GUUS
-
Feb 28th, 2002, 10:54 AM
#9
Hyperactive Member
I know guess its my age
-
Feb 28th, 2002, 11:20 AM
#10
Bouncy Member
Snap
Snap
Snap

damn it took me over half an hour to type that...
-
Feb 28th, 2002, 12:10 PM
#11
Thread Starter
New Member
Thanks
I decided to go with the advice to eliminate error handling for the inner subs so that the error bubbled to the outside sub.
Since the application imports data from several linked excel files, my next dilemma was to capture the name of the excel file which the inner sub was acting upon when the error occured, so the user would know which excel file to fix/format correctly. To deal with that, I created a global variable (outside of all the subs) and set it to the name of the linked excel file it was trying to import at that moment from the inner sub which acted upon the excel file.
Thanks for all your help.
-
Mar 1st, 2002, 04:12 AM
#12
Bouncy Member
-
Mar 1st, 2002, 05:12 AM
#13
Hyperactive Member
Why not use this file name variable for error checking
?
Set it to ""
If it gets a name in it then theres an error.
Save a little bit space
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|