Class Terminates without notice

  • Thread starter Thread starter George Hester
  • Start date Start date
G

George Hester

I tried putting a msgbox in my Class's event-handler for the Class Terminate
sub. Trouble is if I shut Outlook down which is the only way of terminating
the class gracefully, I get a write to memory location error. Thus I cannot
keep the msgbox in that sub. But after a few hours I notice my class is no
longer working. I have to close Outlook 2000 and reopen it to initialize
the Class. In any case even when the class stops working and I have a
msgbox in the terminate event-handler, I do not get notified that the class
has terminated.

So my question is there some way I can get a notification the class has
crapped?
 
For me it's not clear what your intention is.

- You can terminate your classes by setting all references to it = Nothing.
Therefore you don't have to shut down Outlook.

- A MsgBox itself in a class terminate is no problem at all. The error must
have another reason.

- If your class terminates on its own then there is an error, which should
be handled by your code.

As I understand you your question should be why the class terminates.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?productid=300120654&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Thu, 1 Feb 2007 22:24:09 -0500 schrieb George Hester:
 
true Michael but if the Class terminates which I assume is what has happened
if the "implementation" is no longer working, then a msgbox in the Class
Terminate Sub should let me know that has happened, eh?

Doesn't happen. So therefore I am at a loss trying to see why the class has
terminated.

Here I can give an example of this. Put a msgbox in one of your Class
Terminate Subs whch you have made in a Outlook 2000 VBA project.. Have it
so that you can tell it no longer works. Now set up a Sub in a module so
that when you run it an error occurs say like this;

Public Sub Test()
Dim n As Long
n = 3&/0&
End Sub

In other words so that you do not have any Error handling here. Now see if
your Class continues to work after you run Test. If it doesn't, did you get
a notification of the event that the Class is no longer working (terminates)
from the msgbox in the Class Terminate Sub?

In this case it is easy enought to determine why the class has stopped.
 
Sorry, but your thinking about 'error handling' is wrong. Your test doesn't
terminate one class module, but it completely stopps the VBA project because
you do not have any error handling. Thus you don't get that MsgBox because
the project isn't running anymore.

In your test error handling could look like this:

Public Sub Test()
On Error Goto ERR_HANDLER
Dim n As Long

n = 3&/0&

Exit Sub
ERR_HANDLER:
MsgBox Err.Description
End Sub

In that case you'd get a MsgBox and, more important, the code doesn't stopp
running because the error is handled.

For you there're two ways now:

1) Add error handler to each methods or
2) Walk through your code step by step and watch where breaks off.

It's clear that #1 is recommended.

BTW: If very good tool is http://www.mztools.com/v3/mztools3.htm
It's for free and with it it's very easy to add code snippets like error
handler.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?productid=300120654&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Fri, 2 Feb 2007 22:17:13 -0500 schrieb George Hester:
 
Ok but it wasn't the sub I wanted you to invertigate. It was the fact that
the Class terminates without the msgbox in the Class Terminate Sub fireing.
It seems to me if the Project stops then the class terminates so we should
get the notice from the msgbox in the Class Terminate Sub. Correct - I
don't understand how a class can terminate without firing the msgbox there.
So by what you are saying it isn't my class that it is terminating it is the
whole Project which terminates. But then that begs the question. How do I
get notified that the Project has terminated when there is no error like the
example I showed you.? It turns out then from what you say, an error in
some procedure may not be the only thing which causes a Project to
terminate. It might just be a Windows issue, eh?
 
You could do a simple test: With the MsgBox in your class module, create an
instance of it and then set the variable to Nothing again. In that case you
get the MsgBox because the class terminates like it's expected. But if a
project crashes then no Terminate procedures would be executed, it's like
calling the really bad command 'End', which also stopps all your code
without execution of any of your cleanup code.

The simple thing is: *If* your project crashes then you won't get any
message. That's not possible because after it chrashed there's no more code
that would be executed. The only way is to catch them beforehand.

Errors are always passed back to the calling procedure, that's handled
automatically. But in the topmost procedure, like e.g. a button click, you
must handle or ignore it.

You can ignore errors by 'On Error Resume Next'. But you should use that
only if you really know that errors in that case/procedure aren't important.
It's absolutely not usefull if you don't know what your code does, which
errors it could raise - and if you must find the error source.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?productid=300120654&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Sun, 4 Feb 2007 00:27:08 -0500 schrieb George Hester:
 
Back
Top