Cancel Button and DoEvents 
Author Message
 Cancel Button and DoEvents

I've got a lengthy process and stuck in a DoEvents so the rest of the
operating system is accessible.  Now I've decided I might want to stick
in a cancel button to stop the lengthy process.  I'm not sure how this
would work.  I've got a sub that contains the lengthy process (file
reading) which is called by a button click.  What would stop the sub?
How is this normally done?  My first thought was to just have a flag
which is set to true in the Cancel button click event - and then in the
sub after the DoEvents check the state and exit the sub if true.  Is
there a better way?

Thanks,
Jennifer

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 Cancel Button and DoEvents
Jennifer,

You're on the right track.  Just read a flag inside the loop just after the
DoEvents, methinks.

Michael


Quote:
> I've got a lengthy process and stuck in a DoEvents so the rest of the
> operating system is accessible.  Now I've decided I might want to stick
> in a cancel button to stop the lengthy process.  I'm not sure how this
> would work.  I've got a sub that contains the lengthy process (file
> reading) which is called by a button click.  What would stop the sub?
> How is this normally done?  My first thought was to just have a flag
> which is set to true in the Cancel button click event - and then in the
> sub after the DoEvents check the state and exit the sub if true.  Is
> there a better way?

> Thanks,
> Jennifer

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 Cancel Button and DoEvents
Thank you!

Jennifer



Quote:
> Jennifer,

> You're on the right track.  Just read a flag inside the loop just
after the
> DoEvents, methinks.

> Michael



> > I've got a lengthy process and stuck in a DoEvents so the rest of
the
> > operating system is accessible.  Now I've decided I might want to
stick
> > in a cancel button to stop the lengthy process.  I'm not sure how
this
> > would work.  I've got a sub that contains the lengthy process (file
> > reading) which is called by a button click.  What would stop the
sub?
> > How is this normally done?  My first thought was to just have a flag
> > which is set to true in the Cancel button click event - and then in
the
> > sub after the DoEvents check the state and exit the sub if true.  Is
> > there a better way?

> > Thanks,
> > Jennifer

> > Sent via Deja.com http://www.deja.com/
> > Before you buy.

Sent via Deja.com http://www.deja.com/
Before you buy.


Wed, 18 Jun 1902 08:00:00 GMT  
 Cancel Button and DoEvents
or use the Tag-property:

============================
Private Sub cmdCancel_Click()
    cmdCancel.Tag = True
End Sub

Private Sub cmdStartLoop_Click()
Dim LoopVar As Long
    cmdCancel.Tag = False
    For LoopVar = 0 To 10000
        Caption = CStr(LoopVar)
        DoEvents
        If cmdCancel.Tag = True Then
            Caption = "Loop canceled"
            Exit Sub
        End If
    Next
    Caption = "Loop ended"
End Sub
============================

Johan.



| Jennifer,
|
| You're on the right track.  Just read a flag inside the loop just after
the
| DoEvents, methinks.
|
| Michael
|

| > I've got a lengthy process and stuck in a DoEvents so the rest of the
| > operating system is accessible.  Now I've decided I might want to stick
| > in a cancel button to stop the lengthy process.  I'm not sure how this
| > would work.  I've got a sub that contains the lengthy process (file
| > reading) which is called by a button click.  What would stop the sub?
| > How is this normally done?  My first thought was to just have a flag
| > which is set to true in the Cancel button click event - and then in the
| > sub after the DoEvents check the state and exit the sub if true.  Is
| > there a better way?
| >
| > Thanks,
| > Jennifer
| >
| >
| > Sent via Deja.com http://www.deja.com/
| > Before you buy.
| >
|
|



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Cancel Button - not solvable with DoEvents

2. Cancel Button - not solvable with DoEvents

3. Cancel Button - not solvable with DoEvents

4. How to Cancel Execution with Cancel Button?

5. Q: When does a Cancel button *mean* Cancel?

6. Cancel Button on InputBox()

7. status bar and cancel button

8. Cancel button on Calendar Dialog form

9. Cancel button doesn't end macro

10. Detecting Cancel button in Insert Cross Reference dialog

11. "Cancel" Button

12. Cancel button gets Illegal operation error--Word 97

 

 
Powered by phpBB® Forum Software