Results 1 to 7 of 7

Thread: Checking Controls for Activity inside a Loop

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    2

    Question

    How can I check to see if a user has clicked a Cancel button while a long for next loop is executing?

    Thanks,
    Kb

  2. #2
    Guest
    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,

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    2
    Thanks! I tried that very technique, but I was missing the DoEvents line... working now.

    Kb

  4. #4
    Guest
    Glad to help

  5. #5
    Guest
    What does the DoEvents mean? Could someone break it down real fast.

  6. #6
    Guest
    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.

  7. #7
    Guest
    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
  •  



Click Here to Expand Forum to Full Width