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

Loop Interrupt

P: n/a
Hello everyone;

I'm kind of new to VB and I am currently reading "Microsoft Visual Basic
..NET Step by Step" by Michael Halvorson. It's a great book and has been
very easy to read. The last time I did anything in VB was back in 1996 when
I was in college. (Wow has it been that long...)

Anyways, I apologize if this is such a n00b question.

I have a while loop that is reading data and writing to a file via
StreamWriter. This while loop is to continue until a variable changes from
1 to, well, anything else actually. On my form I have a start and stop
button for this action. The start button sets said variable to 1 and then
executes the while loop gathering data and writing it to file. The stop
button simply sets the aforementioned variable to 0. However, once the
while loop starts it never gives control back. You never have a chance to
hit the stop button! I end up having to kill the program. I'm sure this is
something stupid. What am I doing wrong?

Jeremy
VB .n00b
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Place the following code inside the loop:

Application.DoEvents()

Windows will handle events now, such as you clicking on the stop button.
"Jeremy Wood" <tu********@dont.friggin.spam.me.hotmail.com> schreef in
bericht news:y4********************@speakeasy.net...
Hello everyone;

I'm kind of new to VB and I am currently reading "Microsoft Visual Basic
.NET Step by Step" by Michael Halvorson. It's a great book and has been
very easy to read. The last time I did anything in VB was back in 1996
when I was in college. (Wow has it been that long...)

Anyways, I apologize if this is such a n00b question.

I have a while loop that is reading data and writing to a file via
StreamWriter. This while loop is to continue until a variable changes
from 1 to, well, anything else actually. On my form I have a start and
stop button for this action. The start button sets said variable to 1 and
then executes the while loop gathering data and writing it to file. The
stop button simply sets the aforementioned variable to 0. However, once
the while loop starts it never gives control back. You never have a
chance to hit the stop button! I end up having to kill the program. I'm
sure this is something stupid. What am I doing wrong?

Jeremy
VB .n00b

Nov 21 '05 #2

P: n/a
you might want to look into using "threads". I am no expert in that
area, it just sounds like thats what you are needing. I have no code
examples, but i know you can search for "vb.net threads" and am sure
you'll get some ideas.

hope that helps a little bit at least.

Nov 21 '05 #3

P: n/a
Add a call to Application.DoEvents() at the end of your loop. This will slow
down the execution of the loop somewhat but it will allow the stop button
event handler to set the variable to 0.

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
http://msmvps.com/windsor/

"Jeremy Wood" <tu********@dont.friggin.spam.me.hotmail.com> wrote in message
news:y4********************@speakeasy.net...
Hello everyone;

I'm kind of new to VB and I am currently reading "Microsoft Visual Basic
.NET Step by Step" by Michael Halvorson. It's a great book and has been
very easy to read. The last time I did anything in VB was back in 1996
when I was in college. (Wow has it been that long...)

Anyways, I apologize if this is such a n00b question.

I have a while loop that is reading data and writing to a file via
StreamWriter. This while loop is to continue until a variable changes
from 1 to, well, anything else actually. On my form I have a start and
stop button for this action. The start button sets said variable to 1 and
then executes the while loop gathering data and writing it to file. The
stop button simply sets the aforementioned variable to 0. However, once
the while loop starts it never gives control back. You never have a
chance to hit the stop button! I end up having to kill the program. I'm
sure this is something stupid. What am I doing wrong?

Jeremy
VB .n00b

Nov 21 '05 #4

P: n/a
Thanks guys! I guess I haven't learned that statement yet. I need to read
alot more I guess.

Jeremy Wood
VB .n00b

"Jeremy Wood" <tu********@dont.friggin.spam.me.hotmail.com> wrote in message
news:y4********************@speakeasy.net...
Hello everyone;

I'm kind of new to VB and I am currently reading "Microsoft Visual Basic
.NET Step by Step" by Michael Halvorson. It's a great book and has been
very easy to read. The last time I did anything in VB was back in 1996
when I was in college. (Wow has it been that long...)

Anyways, I apologize if this is such a n00b question.

I have a while loop that is reading data and writing to a file via
StreamWriter. This while loop is to continue until a variable changes
from 1 to, well, anything else actually. On my form I have a start and
stop button for this action. The start button sets said variable to 1 and
then executes the while loop gathering data and writing it to file. The
stop button simply sets the aforementioned variable to 0. However, once
the while loop starts it never gives control back. You never have a
chance to hit the stop button! I end up having to kill the program. I'm
sure this is something stupid. What am I doing wrong?

Jeremy
VB .n00b

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.