Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Close Msgbox

2,112 views
Skip to first unread message

Vince

unread,
May 10, 2005, 9:34:23 PM5/10/05
to

I have many functions in my VB project and they all have a stereotypical
errorhandler routine (far from the best but stops the program from crashing
on errors)

Function Blah
on error goto ErrorDescription:


goto ex:
ErrorDescription:
msgbox (err.description & " was encountered....")
ex:
end function

Now, the software is being moved to another location where the network
connection is pretty pathetic and very often, this results in disconnection.
On these occasions, when the functions try to access the SQL Server, the
users get a "Connection failure" from my error handler (the recordset cannot
be opened because the network connection is broken). So, I thought it would
be best if I could try to write some code where the software would attempt
to recover itself on broken connections. Changing each function's
errorhandler is a lot of work (should have been done in the initial stages),
so I thought I would get a Timer to run every 10 seconds and do something
like:

on error goto errordescription:
if sqlconnection.state<>adstateconnected
sqlconnection.open connectionstring
msgbox "Attempted to recover"
endif
goto ex:
errordescription:
msgbox "could not recover. Will retry in 10 minutes"
ex:

When I do the "Attempted to recover" I want all the existing "Connection
failure messages" to be closed (they are, of course, modal message boxes).
Is it possible to close all the message boxes this way? Is my salvage
approach correct? I have only one connection to the SQL Server running
through the life of the software. Please comment.

Thanks,

Vince


Randy Birch

unread,
May 10, 2005, 9:57:27 PM5/10/05
to
If you're using VB6 you can define a function in a bas module called MsgBox
and VB will call that procedure instead of its built-in method, removing the
requirement to recode your error routines. You could then use the code from
either http://vbnet.mvps.org/code/hooks/messageboxhooktimer.htm or
http://vbnet.mvps.org/code/hooks/messageboxhooktimerapi.htm in this MsgBox
function which would allow you to set the messagbox to automatically close
itself once the period you specify has elapsed. This will remove the
requirement to try to find and close any other message boxes generated.

If you use this method in a routine and name it MsgBox, you can still invoke
the real message box if required by prefacing it with "VBA" ...

VBA.MsgBox "the real deal"

But, I also have to comment on the use of message boxes in general. I too
was faced with this type of problem and instead opted for a writing the
error data to both a file (for later tracing) and to a listbox on the form
(e.g. on an "errors" tab). The only time I threw up a dialog was when the
network went down, because that required user intervention. Self-recovering
errors were simply logged to the file/list for review if required.

--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
----------------------------------------------------------------------------
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
----------------------------------------------------------------------------

"Vince" <sd...@fsd.com> wrote in message
news:O3yFSmcV...@TK2MSFTNGP12.phx.gbl...
:
: I have many functions in my VB project and they all have a stereotypical

:
:

Vince

unread,
May 11, 2005, 3:57:16 AM5/11/05
to
Thanks a lot Randy. I'll try to use this Message box and modify it so that
it handles the error handler as well.

Vince

"Randy Birch" <rgb_rem...@mvps.org> wrote in message
news:ucQwJzcV...@TK2MSFTNGP12.phx.gbl...

0 new messages