EDN Admin
Well-known member
I have a form which I use to read data from a text file and export it to an excel template file. The data it reads is constantly updated so I would like to add a check box to cause the data to be read every 10 seconds. Its set up so the user
can either do one quick scan by clicking a button, or they can click the button while also having the check box checked and it will scan every 10 seconds.The problem is, once I check the check box, I cant uncheck it. I have created a greatly simplified
version of my original code to demonstrate this concept.
Imports System.IO
Public Class Form1
Dim checkbox As Boolean
Dim counter As Integer
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
counter = 0
End Sub
Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
checkbox = True
Else
checkbox = False
End If
End Sub
Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Beginning:
System.Threading.Thread.Sleep(3000)
counter = counter + 1
MsgBox(counter)
If checkbox = True Then
GoTo Beginning
Else
Exit Sub
End If
End Sub
End Class
My question is, how do I allow the check box to be changed while the code associated with the button is running so that when checkbox is false, the code will stop running?
View the full article
can either do one quick scan by clicking a button, or they can click the button while also having the check box checked and it will scan every 10 seconds.The problem is, once I check the check box, I cant uncheck it. I have created a greatly simplified
version of my original code to demonstrate this concept.
Imports System.IO
Public Class Form1
Dim checkbox As Boolean
Dim counter As Integer
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
counter = 0
End Sub
Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
checkbox = True
Else
checkbox = False
End If
End Sub
Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Beginning:
System.Threading.Thread.Sleep(3000)
counter = counter + 1
MsgBox(counter)
If checkbox = True Then
GoTo Beginning
Else
Exit Sub
End If
End Sub
End Class
My question is, how do I allow the check box to be changed while the code associated with the button is running so that when checkbox is false, the code will stop running?
View the full article