
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.
| >
|
|