473,320 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Loop Interrupt

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
4 4435
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException....
13
by: na1paj | last post by:
here's a simple linked list program. the DeleteNode function is producing an infinit loop i think, but i can't figure out where.. #include <stdio.h> typedef struct { char *str; //str is a...
2
by: Hartmut | last post by:
Hi guys out there..., I am not shure if this is the right forum for my Question. Have a problem using my own Keyboard interrupt handler. The handler works fine as long as i do not press keys...
14
by: Bill Nguyen | last post by:
The Timer loop below consumes all available CPU time from my development PC. I would like to be able to restrict its use of CPU time to minimum since it's not actually doing anything but counting...
12
by: usa-99 | last post by:
Hi there I have following function which is called on load of page. function checkFieldContent(form) { var field; for(i = 0; i < form.elements.length; i++) { field = form.elements; if...
16
by: Claudio Grondi | last post by:
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of...
43
by: dev_cool | last post by:
Hello friends, I'm a beginner in C programming. One of my friends asked me to write a program in C.The purpose of the program is print 1 to n without any conditional statement, loop or jump. ...
9
by: nunzio | last post by:
Hi, my problem is apparently simple: I have a while loop controlled by a flag and I want to interrupt it by clicking on a stop button. void buttonStart_Click( Object * sender, System::EventArgs *...
44
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.