Re: Error Handlers for VB6

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Ken Halter (Ken_Halter_at_Use_Sparingly_Hotmail.com)
Date: 03/23/05


Date: Wed, 23 Mar 2005 07:39:10 -0800


"dm4714" <spam@spam.net> wrote in message
news:eEs$uo7LFHA.436@TK2MSFTNGP09.phx.gbl...
>I have a VB6 application that updates a SQL Server database. The program
>works fine, but sometimes I receive SQL errors due to bad input or misisng
>information. I'm exeuting a bunch of SP that return various information.
>
> I have an Error Handler in my function and it is trapping for errors.
>
> 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.

Most of my apps do something like this.... when a user does something that
would take a while, Call EnableControls(False)... disables controls and sets
the mouse pointer. When it's done, error or not, Call
EnableControls(True)... enables controls and sets the mouse pointer.
'===============
Option Explicit

'this represents something a user would actually do (besides click on the
form <g>)
Private Sub Form_Click()
   'fwiw, CodeSmart 2005 adds the error handling code with a single
keystroke (including the horizontal "lines")
   Const ErrorLocation = "Form_Click"
   On Error GoTo ErrorTrap
'==============================================================
   Dim f As Single

   'Disable the controls
   Call EnableControls(False)

   'do some work
   f = Timer + 3 '3 seconds
   Do While f > Timer
      DoEvents
   Loop
'==============================================================
Terminate:
   'Enable the controls
   Call EnableControls(True)

   Exit Sub

ErrorTrap:
   MsgBox "Error " & Err.Number & vbCrLf & Err.Description
   Debug.Assert False 'Stops here in the IDE
   Resume Terminate
   Resume 'In the IDE, jump here to find the line that raised the error.
End Sub

Private Sub EnableControls(State As Boolean)
   Dim c As Control
   Me.MousePointer = IIf(State, vbArrow, vbHourglass)
   For Each c In Controls
      c.Enabled = State
   Next
   DoEvents
End Sub
'===============

-- 
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Sign up now to help keep VB support alive - http://classicvb.org/petition
Please keep all discussions in the groups.. 


Relevant Pages

  • Referencing A Subprocedures Name (Re-post)
    ... The textboxes I'm using are not on a form, ... The trick is to iterate through all the controls, ... >Sub PastReply ... >checkboxes to the collection that hosts the classes. ...
    (microsoft.public.excel.programming)
  • Re: recordsetclone mis-usage?
    ... When I say select all the controls, I literally mean "select ALL the ... In comboGOTOotherrecord_afterupdate, you still need the .Edit, because ... Sub Newscreenchangectlcolor() ... sometimes I get an error message: ...
    (microsoft.public.access.formscoding)
  • Re: TabStrip control with XP Themes
    ... Public Sub Hook ... You'll need the API ... > private defWindowProc as long ... Most things work fine except for controls that sit ...
    (microsoft.public.vb.controls)
  • Re: Event wanted
    ... This is the sub as well as the event I use for calling the sub: ... The class EntryCaption is merely a Label with an additional property ... Label object and add it to the controls collection of the parent of the ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Event wanted
    ... This is the sub as well as the event I use for calling the sub: ... The class EntryCaption is merely a Label with an additional property ... Label object and add it to the controls collection of the parent of the ...
    (microsoft.public.dotnet.languages.vb)