Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Progress Bar response

Status
Not open for further replies.

sony2000

Programmer
Dec 7, 2003
34
HK
Hi,

I am a newbie to VB.NET and I hope some experts can help
me to solve my problem. My program has a window form
with a progressbar in it. When my program starts
running and the progressbar displays the % progress,
I try to click "cancel" to terminate the running on
the progress bar window form. But it gets no response
until the progress bar until 100%.....does any know
what coding in VB.NET can make the progress bar
(it is a for-loop in it) to response to other events
during its running?

Thanks for your kind attention,
Raymond
 
When you use a for .. next loop you always run all values
in it.
consider changeing to a do while ... loop
this loop stucture is more flexible
example
j = 100
stop = false
do while j <= 100 and not stop
j = j + 1
if <<insert event here>> then
stop = true
end if
loop


if it is to be it's up to me
 
With respect, I think that the last answer is partially a red herring. To exit from a for loop, you just use "exit for". Also, what does <<insert event here>> mean? The bit about using a boolean called stop is correct, though.

But either way will not work unless you do something to allow the click event to be registered while the loop is still executing. The simplest "something" is to call application.DoEvents every so often.

So, in summary

Declare a boolean at class level called stop.

Have your cancel button click event set this to true.

Before your loop starts, set it to false.

Use the mod function to test for "every so often". (Look up mod in help)

Every so often, first call DoEvents, which will allow the click to be processed, and if your class boolean is now true, exit the loop using exit for.

Mark [openup]
 
Thanks to Mark and infinitelo advice.

Mark's suggestion is a solution that I am looking for
in VB.NET. Thanks.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top