Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


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

Trapping Cancel Button

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

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


Loop
Any info would be appreciated.

Answer:
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:

Do
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
Loop
DevX Pro
 
Comment and Contribute

 

 

 

 

 


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

 

 

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