|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Loop InterruptI'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 Place the following code inside the loop:
Application.DoEvents() Windows will handle events now, such as you clicking on the stop button. Show quoteHide quote "Jeremy Wood" <turbobuick@dont.friggin.spam.me.hotmail.com> schreef in bericht news:y4-dnVJwK87M5dTfRVn-1A@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 > 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. 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. Show quoteHide quote "Jeremy Wood" <turbobuick@dont.friggin.spam.me.hotmail.com> wrote in message news:y4-dnVJwK87M5dTfRVn-1A@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 > Thanks guys! I guess I haven't learned that statement yet. I need to read
alot more I guess. Jeremy Wood VB .n00b Show quoteHide quote "Jeremy Wood" <turbobuick@dont.friggin.spam.me.hotmail.com> wrote in message news:y4-dnVJwK87M5dTfRVn-1A@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 > |
|||||||||||||||||||||||