How can I check to see if a user has clicked a Cancel button while a long for next loop is executing?
Thanks,
Kb
Printable View
How can I check to see if a user has clicked a Cancel button while a long for next loop is executing?
Thanks,
Kb
Hello there,
Well it's kind of a quick and dirty way but it does work.
Hopes this helps,Code:Option Explicit
Dim bClick As Boolean
Private Sub Command1_Click()
Dim I As Long
For I = 0 To 1000000
Label1.Caption = I
Label1.Refresh
If bClick = True Then
MsgBox "Got it!"
bClick = False
Exit For
End If
DoEvents
Next I
End Sub
Private Sub Command2_Click()
bClick = True
End Sub
Private Sub Form_Load()
bClick = False
End Sub
Thanks! I tried that very technique, but I was missing the DoEvents line... working now.
Kb
Glad to help :)
What does the DoEvents mean? Could someone break it down real fast.
DoEvents - Yields execution so that the operating system can process other events.
It basically finished one process before moving on to the next.
Hope that helps a bit.Code:Private Sub Command1_Click()
For i = 0 to 100 'count to 100
List1.additem i:DoEvents
'Add to list and make sure it's doing everything it's suppose to.
'And after it's done processing events
'it moves on and count the next i (number)
Next i
End Sub
A better mthod is to use the AsynchKeyState api call. This doesn't make the app relinquish (sp?) control of the processor as badly.
- gaffa