Interrupting Loop

ayozzhero

Well-known member
Joined
Apr 6, 2005
Messages
186
Location
Malaysia
Programming Experience
1-3
Let say in frmProcess I put a For..Next loop. While looping, how do I detect if user presses btnCancel and then terminate the looping process.

Thank you.

P/s: By the way, is there anyway I can appreciate you people for entertaining so many questions from me... e.g. give good rating etc... etc :)
 
Put the code that performs the loop in a separate sub and then use the click
event of the button to set the boolean variable ... ;)

VB.NET:
[/color][/size][size=2][color=#0000ff]If[/color][/size][size=2] ItRuns = [/size][size=2][color=#0000ff]True[/color][/size][size=2] [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]ItStop = [/size][size=2][color=#0000ff]True

[/color][/size][size=2][/size][size=2][color=#0000ff]Else

[/color][/size][size=2]YourSub()

ItRuns = [/size][size=2][color=#0000ff]True

[/color][/size][size=2][/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If[/color][/size]
[size=2][color=#0000ff]

If you don't find this useful let me know and i'll make a demo ... ;)
 
Thank you Kulrom. It works, and I see the magic is in the 'Application.DoEvents'. But I just do not understand your remarks:

Application.DoEvents() 'btw, a DoEvents loop uses 100% processor time ... so, be careful when you use that

I mean, is there any implication of using the Application.DoEvents() ?
 
Back
Top