Results 1 to 7 of 7

Thread: Cancel button help

Hybrid View

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    39

    Cancel button help

    Well, this is similar to my other thread. Anyways, I want to have a "stop" or "cancel" button, that immediately stops the loop where it is. Not when it finishes.

    Here is my current code:
    VB Code:
    1. Private Sub start_Click()
    2. stopp = True
    3.  
    4. Do Until stopp = False
    5. If stopp = False Then
    6. Exit Do
    7. End If
    8. DoEvents
    9.  
    10.  
    11. EventPause ("5")
    12. SendKeys ("message")
    13. EventPause ("1")
    14. SendKeys ("message1")
    15. EventPause ("1")
    16. SendKeys ("message2")
    17. EventPause ("1")
    18. SendKeys ("message3")
    19. EventPause ("1")
    20. SendKeys ("message4")
    21. EventPause ("1")
    22. SendKeys ("message5")
    23. EventPause ("1")
    24. SendKeys ("message6")
    25. EventPause ("1")
    26. SendKeys ("message7")
    27. EventPause ("1")
    28. SendKeys ("message8")
    29. EventPause ("1")
    30. SendKeys ("message9")
    31. EventPause ("1")
    32. SendKeys ("message10")
    33. EventPause ("1")
    34. SendKeys ("message11")
    35. EventPause ("1")
    36. DoEvents
    37. Loop
    38.  
    39. End Sub
    40.  
    41. 'Cancel button
    42. Private Sub Command1_Click()
    43. stopp = False
    44. End Sub

    However, this only stops the loop once it is completed and back to the start. Maybe I am using DoEvents wrong? Could somone please modify my code so the split second the "stop" button is pushed the loop stops?

    Again: it stops fine, but only once the loop is completed. I want to stop mid-loop the second the stop button is pushed.

    Thanks!

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Cancel button help

    if you put your stopp test between every line it will stop befor the next

    VB Code:
    1. Private Sub start_Click()
    2. stopp = True
    3.  
    4. Do Until stopp = False
    5. If stopp = False Then Exit Do
    6.  
    7. DoEvents
    8.  
    9.  
    10. EventPause ("5")
    11. If stopp = False Then Exit Do
    12. SendKeys ("message")
    13. EventPause ("1")
    14. If stopp = False Then Exit Do
    15. SendKeys ("message1")
    16. EventPause ("1")
    17. If stopp = False Then Exit Do
    18. SendKeys ("message2")
    19. EventPause ("1")
    20. If stopp = False Then Exit Do
    21. SendKeys ("message3")
    22. EventPause ("1")
    23. If stopp = False Then Exit Do
    24. SendKeys ("message4")
    25. EventPause ("1")
    26. If stopp = False Then Exit Do
    27. SendKeys ("message5")
    28. EventPause ("1")
    29. If stopp = False Then Exit Do
    30. SendKeys ("message6")
    31. EventPause ("1")
    32. If stopp = False Then Exit Do
    33. SendKeys ("message7")
    34. EventPause ("1")
    35. If stopp = False Then Exit Do
    36. SendKeys ("message8")
    37. EventPause ("1")
    38. If stopp = False Then Exit Do
    39. SendKeys ("message9")
    40. EventPause ("1")
    41. If stopp = False Then Exit Do
    42. SendKeys ("message10")
    43. EventPause ("1")
    44. If stopp = False Then Exit Do
    45. SendKeys ("message11")
    46. EventPause ("1")
    47. If stopp = False Then Exit Do
    48. DoEvents
    49. Loop
    50.  
    51. End Sub

    rgds pete

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    39

    Re: Cancel button help

    What if one of my SendKeys were say 1,000 charectors+ and it took a fair bit of time, and I wanted to stop mid-way through the send keys?

    If possible I want to be able to stop the EXACT second without it processing anything further... possible?

    Isn't there like a "Kill" all active processes in the program, so it stops everything and just returns to idle?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Cancel button help

    if you want to stop in the middle of prossesing a single instruction, there maybe a way to do it useing an api call

    the only other way is to end your program, which is not a good way to do anything and other members here will say don't do that, otherwise it has to finish each instruction before it can process the next, exit loop


    p.

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    39

    Re: Cancel button help

    Any idea what the API call is?

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Cancel button help

    sorry can't help with that, only said there maybe an api

    the only way i can think of to make it work would be to put it in a timer, so that it is looping separatly to the loop you are processing

    p.

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