Results 1 to 3 of 3

Thread: Interrupting the program flow

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2000
    Posts
    35

    Question

    I'd like to add a Cancel button to a form whereby I could interrupt a certain program task, typically a time-consuming one, for example:

    for i1=1 to largeNumber1
    for i2=1 to LargeNumber2
    WorkOnSomethingCumbersome
    next
    next

    How can I have the cancel button take me out of the loops and to the exit point of the procedure?

  2. #2
    Guest
    Couldn't you have something like this? There is probably a more efficient way but:

    Code:
    Dim Canceled as Boolean
    
    Private Sub cmdCancel_Click()
    Canceled = True
    End Sub
    THEN

    Code:
    for i1=1 to largeNumber1 
     for i2=1 to LargeNumber2 
      If Canceled = True Then Exit For ' or exit sub/function
      WorkOnSomethingCumbersome
    next i2

  3. #3
    Member
    Join Date
    Oct 2000
    Location
    Netherlands
    Posts
    54

    Exclamation Dont forget the DoEvents

    That code looks good, but don't forget to put DoEvents in your code to give the user the opportunity to click on the cancel button. Also disable all other things he may not use during the proces. But you probably thought about this anyway.
    A mind is like a parachute, it has to open to let it work
    www.2beesoft.com for Icon Manager with over 20.000 free icons
    VB6 Ent. SP4, ASP, W2000/W98

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