By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

Is this the way to check for Esc

P: n/a
When I need to cancel when Esc is pressed this is what I do:

In KeyUp I set a module level variable if Esc is pressed.

Where I want to check for cancel I do a DoEvents and then check that
variable.

This is probably a long loop so DoEvents is executed often and I takes a
performance hit.

Is there a better way?

Thanks

Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

" Just Me" <ne********@a-znet.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
When I need to cancel when Esc is pressed this is what I do:

In KeyUp I set a module level variable if Esc is pressed.

Where I want to check for cancel I do a DoEvents and then check that
variable.

This is probably a long loop so DoEvents is executed often and I takes a
performance hit.

Is there a better way?


You could execute the long-running process on a secondary thread and let the
main (UI) thread process user input as normal. That's about all I can think
of to avoid DoEvents.
Nov 20 '05 #2

P: n/a
Thanks, I've done something like that.
Bumped a counter and did DoEvents and rest the counter when it reached some
value

Thanks
"Jonathan Allen" <Jo***********@discussions.microsoft.com> wrote in message
news:61**********************************@microsof t.com...
Avoiding DoEvents is a good thing. But if you don't wnat to deal with threads, you can limit how often it is called.
For X = 1 To 1000000
'some code

If X Mod 100 = 0 Then DoEvents()
Next

This will call DoEvents only once for every 100 iterations.

Jonathan Allen

"Just Me" wrote:
When I need to cancel when Esc is pressed this is what I do:

In KeyUp I set a module level variable if Esc is pressed.

Where I want to check for cancel I do a DoEvents and then check that
variable.

This is probably a long loop so DoEvents is executed often and I takes a
performance hit.

Is there a better way?

Thanks

Nov 20 '05 #3

P: n/a
I'm going to keep that in mind. I haven't yet used secondary threads but
maybe I should be thinking that way.

Thanks

"Jeff Johnson [MVP: VB]" <i.***@enough.spam> wrote in message
news:e6****************@TK2MSFTNGP11.phx.gbl...

" Just Me" <ne********@a-znet.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
When I need to cancel when Esc is pressed this is what I do:

In KeyUp I set a module level variable if Esc is pressed.

Where I want to check for cancel I do a DoEvents and then check that
variable.

This is probably a long loop so DoEvents is executed often and I takes a
performance hit.

Is there a better way?
You could execute the long-running process on a secondary thread and let

the main (UI) thread process user input as normal. That's about all I can think of to avoid DoEvents.

Nov 20 '05 #4

P: n/a
One other thing I forgot to ask:

The code is on a UserControl which contains many controls.

Do I have to code each KeyUp or can I some how get the UserControl's KeyUp
event to catch them all?

I know I can make one method handle all the events, but is that necessary?

Guess I'm looking for a KeyPreview for a UserControl.
Thanks


" Just Me" <ne********@a-znet.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
When I need to cancel when Esc is pressed this is what I do:

In KeyUp I set a module level variable if Esc is pressed.

Where I want to check for cancel I do a DoEvents and then check that
variable.

This is probably a long loop so DoEvents is executed often and I takes a
performance hit.

Is there a better way?

Thanks

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.