NssB
Member
- Joined
- May 11, 2007
- Messages
- 13
- Programming Experience
- Beginner
Hi all,
Looking for help with a VB.NET form issue. Have a button which runs a Do Loop until a variable is set by the click event of another button. However, the Button which starts the logging routine remains depressed until I click elsewhere on the form.....more of an annoyance issue, which requires a click anywhere on the form before you can click the 'Stop Logging' button(or two clicks on that button, if you like.)
Code:
Looking for help with a VB.NET form issue. Have a button which runs a Do Loop until a variable is set by the click event of another button. However, the Button which starts the logging routine remains depressed until I click elsewhere on the form.....more of an annoyance issue, which requires a click anywhere on the form before you can click the 'Stop Logging' button(or two clicks on that button, if you like.)
Code:
VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] GlassButton1_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] startButton.Click[/SIZE]
[SIZE=2][COLOR=#008000] 'run startlogging subroutine[/COLOR][/SIZE]
[SIZE=2] loggingState = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] If[/COLOR][/SIZE][SIZE=2] radioDetailed.Checked = [/SIZE][SIZE=2][COLOR=#0000ff]True [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2] logDetailed()[/SIZE]
[SIZE=2][COLOR=#0000ff] Else[/COLOR][/SIZE]
[SIZE=2] logBasic()[/SIZE]
[SIZE=2][COLOR=#0000ff] End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] logDetailed()[/SIZE]
[SIZE=2][COLOR=#008000]'start logging detailed stuff[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Do[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]While[/COLOR][/SIZE][SIZE=2] loggingState <> [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000] 'slow the loop down[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] timeOut [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DateTime = Now.AddMilliseconds(200)[/SIZE]
[SIZE=2][COLOR=#0000ff] Do[/COLOR][/SIZE]
[SIZE=2] Application.DoEvents()[/SIZE]
[SIZE=2][COLOR=#0000ff] Loop[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Until[/COLOR][/SIZE][SIZE=2] Now > timeOut[/SIZE]
[SIZE=2][COLOR=#008000]'read in the text file line by line[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] oRead [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.IO.StreamReader[/SIZE]
[SIZE=2]oRead = IO.File.OpenText([/SIZE][SIZE=2][COLOR=#800000]"C:\sample.txt"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]While[/COLOR][/SIZE][SIZE=2] oRead.Peek <> -1[/SIZE]
[SIZE=2] logText.Text += oRead.ReadLine() & vbCrLf[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]While[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Loop[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] GlassButton2_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] stopButton.Click[/SIZE]
[SIZE=2][COLOR=#008000]'Set the logging state to false to stop the logging routine[/COLOR][/SIZE]
[SIZE=2]loggingState = [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]