Re: Error Handlers for VB6
From: Tony Proctor (tony_proctor_at_aimtechnology_NoMoreSPAM_.com)
Date: 03/24/05
- Next message: J French: "Re: Error Handlers for VB6"
- Previous message: Mark J. McGinty: "Re: Visual Basic 6 and memory usage"
- In reply to: Larry Serflaten: "Re: Error Handlers for VB6"
- Next in thread: J French: "Re: Error Handlers for VB6"
- Reply: J French: "Re: Error Handlers for VB6"
- Reply: Bob O`Bob: "Re: Error Handlers for VB6"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 24 Mar 2005 08:11:34 -0000
I've seen a few examples of code that would break without DF Larry, most of
which involve holding some resource or lock as opposed to just dynamic
memory. However, this is a very crisp and simple demonstration of the need
for DF. I use that technique so much that I didn't even consider that it
depended so much on that feature.
I heard a rumour that the .Net framework was currently being reviewed to
optionally allow DF through the IDispose interface. Sorry I don't have any
concrete details - I've only had this second-hand. Can anyone confirm that?
Tony Proctor
"Larry Serflaten" <serflaten@usinternet.com> wrote in message
news:eGjd5U8LFHA.4092@tk2msftngp13.phx.gbl...
>
> "dm4714" <spam@spam.net> wrote
>
> > My problem is, however, that I've changed my mouse pointer to an hour
glass
> > while the SQL queries are running. When I do get an error and the error
> > handler is invoked, control is returned to my main form and the mouse
> > pointer is still an hour glass.
> >
> > Now I realize I can simply put it back to normal within my error
handler...
> > but is this the best way to do this?
> >
> > If I have various checks for valid data within my function and attempt
to do
> > an "Exit Sub" instead of using the error handler, is there a recommended
way
> > to handle resetting the mouse pointer back?
> >
> > Perhaps adding something to my main form activate event?
> >
> > Any ideas/recommendation/best practices would be appreciated.
>
>
> You happened to hit on a topic that was beaten to death when .Net first
came
> out. .Net did not (easily) support deterministic finalization (meaning
objects
> were not destroyed when all references were released as happens in VB6.
In
> .Net the Garbage Collector has to come by to do the clean up.)
>
> One example that was used to show why DF was a good thing was the
> mouse pointer dilema you have found yourself in the middle of. You could
> add a label to your routine's exit point and place the mouse code there,
making
> sure all exits go through that one exit point. But what if you want to
raise the
> error, or handle it, etc... You end up with mulitple statements no matter
how
> you go about it....
>
> A clever fix is to create a class that you instantiate at the start of
your routine.
> No matter how you exit that routine, VB will drop the reference to that
class
> as it exits. You can use that fact to your advantage....
>
> ' [HourGlass Class code]
> Private Sub Class_Initialize()
> Screen.MousePointer = vbHourglass
> End Sub
>
> Private Sub Class_Terminate()
> Screen.MousePointer = vbDefault
> End Sub
>
>
> When that object is created, it will set the mousepointer to an hourglass.
And,
> when that object is destroyed, it will return the mousepointer to its
default value.
>
> To use it, you simply create an instance of that object at the start of
the routine
> and that's it. No matter how the routine exits, VB will drop the
reference causing
> the object to be destroyed:
>
> Private Sub Form_Click()
> Dim Cursor As HourGlass
> Set Cursor = New HourGlass
> ' Any and all code....
> MsgBox "Waiting..." 'to see it was set to HourGlass
> End Sub
>
>
> See it that might suit your needs.....
> LFS
>
>
- Next message: J French: "Re: Error Handlers for VB6"
- Previous message: Mark J. McGinty: "Re: Visual Basic 6 and memory usage"
- In reply to: Larry Serflaten: "Re: Error Handlers for VB6"
- Next in thread: J French: "Re: Error Handlers for VB6"
- Reply: J French: "Re: Error Handlers for VB6"
- Reply: Bob O`Bob: "Re: Error Handlers for VB6"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|