Updating a Gauge and Detecting a User Interrupt (Access 2.0)

Take the following steps to update a gauge during processing and detect a user interrupt:

1. Start with the project that you created in Loading and Displaying an Image.

2. image\btncmd.gif Select the Command Button control; then add the control to your main form. Put the control at the top of the form to keep it away from the image.

3. In the Properties box, change the Command Button control's Name property to Do Median.

4. image\btncmd.gif Select the Command Button control; then add another control to your main form. Put the control at the top of the form to keep it away from the image.

5. In the Properties box, change the Command Button control's Name property to Quit.

6. Build a gauge consisting of a horizontal line image\btnline2.gif (Line1) inside a rectangle image\btnrctl.gif (Box1). Put the gauge at the top of the form next to the Quit button.

7. Add the following code to the general declarations:

Dim fEscape As Integer 'Use to indicate the user interrupt
Dim fInProc As Integer 'Use to avoid closing the form during processing

8. Add the following code to the first Command Button control's Click procedure:

Sub Button16_Click ()
  'Enable the ProgressStatus event
  Me![LEAD1].Object.EnableProgressEvent = True

  'Initialize the indicators
  fEscape = False 'The user does not want to quit
  fInProc = True 'Processing is taking place

  'Perform a relatively slow median filter
  Me![LEAD1].Object.Median 4

  'Clean up
  fInProc = False 'Processing is no longer taking place
  Me![LEAD1].Object.ForceRepaint
End Sub

9. Add the following code to the Lead1 control's ProgressStatus procedure:

Sub LEAD1_ProgressStatus (iPercent As Integer)
  DoEvents 'Detect Windows events
  If Not fEscape Then ' Look for the Click on the Quit button
    Me![Line1].Width = Me![Box1].Width * iPercent / 100 'Udpate the gauge
  Else
    Me![LEAD1].Object.EnableProgressEvent = False 'Cancel the task
  End If
End Sub

10. Add the following code to the second Command Button control's Click procedure:

Sub Button17_Click ()
  fEscape = True 'The user wants to quit
  Me![Line1].Width = 0 'Set the gauge back to the beginning
End Sub

11. Add the following code to the Form Unload procedure:

Sub Form_Unload (Cancel As Integer)
  If fInProc Then 'If processing is taking place
  Cancel = 1 'Do not let the user close the form
  End If
End Sub

12. Run your program to test it.