click event won't work in cancel button 
Author Message
 click event won't work in cancel button
When my VB program is doing a task, even the user click *cancel* button. The
program still not fire that event to the OS to stop the current task. Any
workarounds to the problem??

Sub cmdcancel_click()
    End
End Sub



Sun, 23 Oct 2005 13:21:55 GMT  
 click event won't work in cancel button
On Tue, 6 May 2003 22:21:55 -0700, "John Davis"

Quote:

>When my VB program is doing a task, even the user click *cancel* button. The
>program still not fire that event to the OS to stop the current task. Any
>workarounds to the problem??

>Sub cmdcancel_click()
>    End
>End Sub

First off, don't use End!  ;-)    You can find out all of the reasons
why by searching these newsgroups via Google.

I suspect your app is running in a tight loop that isn't giving a
chance for the event to fire.  If you insert a call to DoEvents into
your loop, it should allow for you code to break and let your cancel
event fire.  You can then figure out some other way, (besides using
End  ;-) ), cancel the loop.

HTH,
Bryan
____________________________________________________________
New Vision Software            "When the going gets weird,"
Bryan Stafford                   "the weird turn pro."

Microsoft MVP-Visual Basic     Fear and Loathing in LasVegas



Sun, 23 Oct 2005 13:38:27 GMT  
 click event won't work in cancel button
Thanks. You mean the following??? So what should I put inside Sub
cmdCancel_Click() ???

For I=1 To 200000
    //Do something
    DoEvents
Next

Sub cmdCancel_Click()
    //What should I use???
End Sub


Quote:
> On Tue, 6 May 2003 22:21:55 -0700, "John Davis"

> >When my VB program is doing a task, even the user click *cancel* button.
The
> >program still not fire that event to the OS to stop the current task. Any
> >workarounds to the problem??

> >Sub cmdcancel_click()
> >    End
> >End Sub

> First off, don't use End!  ;-)    You can find out all of the reasons
> why by searching these newsgroups via Google.

> I suspect your app is running in a tight loop that isn't giving a
> chance for the event to fire.  If you insert a call to DoEvents into
> your loop, it should allow for you code to break and let your cancel
> event fire.  You can then figure out some other way, (besides using
> End  ;-) ), cancel the loop.

> HTH,
> Bryan
> ____________________________________________________________
> New Vision Software            "When the going gets weird,"
> Bryan Stafford          "the weird turn pro."

> Microsoft MVP-Visual Basic     Fear and Loathing in LasVegas



Sun, 23 Oct 2005 14:24:55 GMT  
 click event won't work in cancel button

Quote:

> Thanks. You mean the following??? So what should I put inside Sub
> cmdCancel_Click() ???

[In general declarations]
Private mbooCancel as Boolean

Quote:
> For I=1 To 200000
>     //Do something
>     DoEvents

        If mbooCancel then Exit [Sub/Function]
Quote:
> Next

> Sub cmdCancel_Click()

        mbooCancel =True
Quote:
> End Sub



Sun, 23 Oct 2005 14:32:16 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. ESC still fires Validating events but clicking the Cancel button does not

2. ActiveX-Exe: .Value=True doesn't work while direct click on button works

3. Click event won't fire on a user control

4. Why Click Event if VB won't respond

5. How to make the button in Usercontrol call Usercontrol's Click event

6. How to get a click event from an option button that's already True

7. My undo and delete button won't work

8. Button events won't fire when editing a cell

9. dbList.BoundColumn doesn't work with MatchEntry in Click event

10. Command Button won't work while in loop

11. dbList.BoundColumn doesn't work with MatchEntry in Click event

12. dbList.BoundColumn doesn't work with MatchEntry in Click event

 

 
Powered by phpBB® Forum Software