Loop inside the check box in vb.net

sonu1992

New Member
Joined
Oct 9, 2014
Messages
1
Hi there,

I am using a if loop inside the check box but somehow it is not running inside the loop until the check box is unchecked. here is the code
Code:
  Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles checkbox.CheckedChanged        If checkbox.Checked = True Then
            txtCnt.Text = intCount   ' displaying the value of intcount to txtCnt.Text i.e. text box in the form
            txtCnt.Update()
            Timer.Interval = 1000
            Timer.Enabled = True
            Timer.Start()
            Dim lngerrorcode As Integer
            Dim lngIDNum As Integer
            Dim intchannel As Integer
            Dim lngDemo As Integer
            Dim intGain As Integer
            Dim lngovervoltage As Integer
            Dim sngvoltage As Single
            lngovervoltage = 0
            sngvoltage = 0
            intchannel = -1
            intGain = -1
            intchannel = 7
            intGain = 0
            intCount = intCount + 1  'increments intcount by 1   
            txtCnt.Text = intCount   ' displaying the value of intcount to txtCnt.Text i.e. text box in the form
            txtCnt.Update()
            lngerrorcode = lj.LabJack.EAnalogIn(lngIDNum, lngDemo, intchannel, intGain, lngovervoltage, sngvoltage)
            txtTemp.Text = sngvoltage
            txtTemp.Update()
            TotalSum += sngvoltage         'adding all the random generated values to total sum every time a random value is generated.
            txtAvg.Text = Format(TotalSum / intCount, "###.")
            txtAvg.Update()
            If sngvoltage > 250 Then ' if the random generated number greater than number entered in text box oh high limit
                txtStatus.Text = "HI" 'display text in anunciator as HI
                txtStatus.BackColor = Color.Red 'back ground color of annunciator as red
                txtStatus.Update()
                badCount += 1 ' increase the bad count by 1
                Me.txtFaildRes.Text = badCount ' display bad count in text box of bad count.
                txtFaildRes.Update()
                lstData2.Items.Add(sngvoltage & vbTab & txtStatus.Text & vbTab & Now) 'adding values to list box with current date and time
                Me.lstData2.Text = Me.txtTemp.Text & vbNewLine & Me.lstData2.Text 'adding temperature values and the status of annunciator to list box
                My.Computer.FileSystem.WriteAllText("C:\temp\lab4.txt", sngvoltage & vbTab & Now & vbCrLf, True)
                lstData2.Update()
            ElseIf sngvoltage < 100 Then
                txtStatus.Text = "LO" ' if not annunciator text status as OK
                txtStatus.BackColor = Color.Gray ' displays back ground color of annunciator as green
                txtStatus.Update()
                badCount += 1 ' increase the bad count by 1
                Me.txtFaildRes.Text = badCount ' display bad count in text box of bad count.
                txtFaildRes.Update()
                lstData2.Items.Add(sngvoltage & vbTab & txtStatus.Text & vbTab & Now) 'adding values to list box with current date and time
                Me.lstData2.Text = Me.txtTemp.Text & vbNewLine & Me.lstData2.Text 'adding temperature values and the status of annunciator to list box
                My.Computer.FileSystem.WriteAllText("C:\temp\lab4.txt", sngvoltage & vbTab & Now & vbCrLf, True)
                lstData2.Update()
            Else
                txtStatus.Text = "OK"
                txtStatus.BackColor = Color.Green
                txtStatus.Update()
                lstData2.Items.Add(sngvoltage & vbTab & txtStatus.Text & vbTab & Now) 'adding values to list box with current date and time
                Me.lstData2.Text = Me.txtTemp.Text & vbNewLine & Me.lstData2.Text 'adding temperature values and the status of annunciator to list box
                My.Computer.FileSystem.WriteAllText("C:\temp\lab4.txt", sngvoltage & vbTab & Now & vbCrLf, True)
                lstData2.Update()
            End If
        ElseIf checkbox.Checked = False Then
            Dim random As New Random 'Declaring random as new random   
            Dim Line1 As New Label   'Declaring line1 as new label   
            Dim Line2 As New Label   'Declaring line2 as new label 
            Dim Line3 As New Label   'Declaring line3 as new label
            intCount = intCount + 1  'increments intcount by 1   
            txtCnt.Text = intCount   ' displaying the value of intcount to txtCnt.Text i.e. text box in the form
            sngR = random.Next(0, 500) 'generates random numbers between 0 to 500.
            txtTemp.Text = sngR     'displays the random generated value in the temperature text box.
            TotalSum += sngR         'adding all the random generated values to total sum every time a random value is generated.
            txtAvg.Text = Format(TotalSum / intCount, "###.") 'dividing the total sum by intCount to find the average of tested values and displays in average text box.
            Call line() 'calls the function Line()
        End If
    End Sub
I connected to a lab jack U12 and the values of the photo resistor is taken when check box is enabled/checked, until I click on the check box/uncheck it again it must not execute the steps below last 'elseif' statement.
can anyone of you help me please
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top