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

How to ESCAPE a long running FOR-NEXT ?

P: n/a
I want EXIT a FOR-NEXT construct via EXIT
if the user presses key ESCAPE

How can I check, whether the user presses ESCAPE
while my program is in the FOR-NEXT construct ??
Peter
Jul 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Peter,

In a windows program you could add a flag (boolean value) that you set on
the Escape key in a KeyPress/Down/Up event.

In your loop, every so often do Application.DoEvents() and then check to
see if the flag is true, if so, break the loop.

--
Happy Coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #2

P: n/a
and how you do it ?
"Morten Wennevik" wrote:
Hi Peter,

In a windows program you could add a flag (boolean value) that you set on
the Escape key in a KeyPress/Down/Up event.

In your loop, every so often do Application.DoEvents() and then check to
see if the flag is true, if so, break the loop.

--
Happy Coding!
Morten Wennevik [C# MVP]

Jul 21 '05 #3

P: n/a
Like this:

class MyForm:Form
{
private mStop=false;
...
//You can change following Click event handler to KeyPress/Down/Up to
capture "ESC" key storke
private btnStop_Click(object sender, Systen,EventHandler e)
{
mStop=true;
}

....

private void DoLengthyLoop()
{
for (i=0; i<1000000; i++)
{
////Do something
Application.DoEvents() ////Or if (i%10==0)
Application.DoEvents(), i.e. every 10 loops, check Stop flag.
if (mStop) break;
}
}

....
}

<Nascimento>; "Daniel" <Na**************@discussions.microsoft.com> wrote in
message news:89**********************************@microsof t.com...
and how you do it ?
"Morten Wennevik" wrote:
Hi Peter,

In a windows program you could add a flag (boolean value) that you set on the Escape key in a KeyPress/Down/Up event.

In your loop, every so often do Application.DoEvents() and then check to
see if the flag is true, if so, break the loop.

--
Happy Coding!
Morten Wennevik [C# MVP]

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.