Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Oct 1, 1996



Application Security Testing: An Integral Part of DevOps

Trapping Cancel Button

In a simple loop on a form with a Cancel Button:

Here I want to Check to see if a user pushed a cancel button
(Cancel Property is set to true)
(While in loop can't get focus to Cancel Button to see
 if it was pushed. Setting focus to it does not work.
 There must be a simple way to trap for this)

 If Cancel is Pushed, Exit Loop

Any info would be appreciated.

What I would do is from the Cancel_Click event, set a flag to True. At the bottom of your loop put a DoEvents statement. This frees up the processor to check for things like button clicks, etc. At the top of your loop, check the flag and if True, exit the loop. Let's say your flag is global and is called gintCancelFlag. Pseudo-code looks something like this:

If gintCancelFlag = True Then Exit Do

'In here you'd put the code the loop is supposed to be doing.

DoEvents ()  'note that the () is necessary
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date