|
-
Sep 27th, 2000, 06:00 PM
#1
Thread Starter
New Member
How can I check to see if a user has clicked a Cancel button while a long for next loop is executing?
Thanks,
Kb
-
Sep 27th, 2000, 06:15 PM
#2
Hello there,
Well it's kind of a quick and dirty way but it does work.
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
Hopes this helps,
-
Sep 27th, 2000, 06:23 PM
#3
Thread Starter
New Member
Thanks! I tried that very technique, but I was missing the DoEvents line... working now.
Kb
-
Sep 27th, 2000, 06:28 PM
#4
Glad to help
-
Sep 27th, 2000, 09:51 PM
#5
What does the DoEvents mean? Could someone break it down real fast.
-
Sep 27th, 2000, 10:01 PM
#6
DoEvents - Yields execution so that the operating system can process other events.
It basically finished one process before moving on to the next.
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
Hope that helps a bit.
-
Sep 27th, 2000, 11:23 PM
#7
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|