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
 

Some videos you may like

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Watch MrExcel Video

Forum statistics

Threads
1,109,202
Messages
5,527,388
Members
409,759
Latest member
KCH

This Week's Hot Topics

Top