Link to home
Create AccountLog in
Avatar of Colin
ColinFlag for United States of America

asked on

Form Load and CheckChange Events at times fire and not fire.

The code below will determine a user interaction with a checkbox. At times on the form load it will execute and other times it will not execute. This throws off my flag set variable at the start of the form load.

Any suggestions on how to handle (or a more efficient way) to solve my issue?

 Private Sub chkTPCalcActive_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkTPCalcActive.CheckedChanged
        Dim GageConfiguration As String
        If TPFormLoaded = True Then
            TPFormLoaded = False
            Exit Sub
        End If
        If Me.chkTPCalcActive.Checked = True Then
            ' If TPCalcSwitchState = True Then
            ActivateTPCalculation = True
            TPCalcSwitchState = True
            GageConfiguration = ("<@:L" & GageID & "08<GAGE,P>")
            serialCOMDiscover.WriteLine(GageConfiguration)
            System.Threading.Thread.Sleep(1000)
            'ElseIf TPCalcSwitchState = True or  Then
            'ActivateTPCalculation = False
            'GageConfiguration = ("<@:L" & GageID & "08<GAGE,P>")
            'serialCOMDiscover.WriteLine(GageConfiguration)
            'System.Threading.Thread.Sleep(1000)
            ' End If
            'TPCalcSwitchState = True
        ElseIf Me.chkTPCalcActive.Checked = False Then
            ActivateTPCalculation = True
            TPCalcSwitchState = True
            GageConfiguration = ("<@:L" & GageID & "08<GAGE,P>")
            serialCOMDiscover.WriteLine(GageConfiguration)
            System.Threading.Thread.Sleep(1000)
        End If
    End Sub

Open in new window

Avatar of Robberbaron (robr)
Robberbaron (robr)
Flag of Australia image

in my experience, changing the checkbox from form load doesnt throw the event....

so you may want to move all the code into a separate (eg) chkTPCalcActions function, which is called from _CheckedChanged

in that way, you can set the checkbox on form load (from a previous settings or similar) and then call the chkTPActions to do other updates
Avatar of Colin

ASKER

OK, but where do I put my function if I move it outside the event?
same code file,
Private Sub chkTPCalcActive_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkTPCalcActive.CheckedChanged

        chkTPCalcActions()
end Sub

Sub chkTPCalcActions()
        Dim GageConfiguration As String
        If TPFormLoaded = True Then
            TPFormLoaded = False
            Exit Sub
        End If
        If Me.chkTPCalcActive.Checked = True Then
            ' If TPCalcSwitchState = True Then
            ActivateTPCalculation = True
            TPCalcSwitchState = True
            GageConfiguration = ("<@:L" & GageID & "08<GAGE,P>")
            serialCOMDiscover.WriteLine(GageConfiguration)
            System.Threading.Thread.Sleep(1000)
            'ElseIf TPCalcSwitchState = True or  Then
            'ActivateTPCalculation = False
            'GageConfiguration = ("<@:L" & GageID & "08<GAGE,P>")
            'serialCOMDiscover.WriteLine(GageConfiguration)
            'System.Threading.Thread.Sleep(1000)
            ' End If
            'TPCalcSwitchState = True
        ElseIf Me.chkTPCalcActive.Checked = False Then
            ActivateTPCalculation = True
            TPCalcSwitchState = True
            GageConfiguration = ("<@:L" & GageID & "08<GAGE,P>")
            serialCOMDiscover.WriteLine(GageConfiguration)
            System.Threading.Thread.Sleep(1000)
        End If
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Colin
Colin
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Colin

ASKER

After taking a closer look on how to handle the event. I was able to set a flag on the form load event so if the event from the radio button was raised it would look to see if the form has been entered or not.