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

cmdolcetAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robberbaron (robr)Commented:
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
0
cmdolcetAuthor Commented:
OK, but where do I put my function if I move it outside the event?
0
Robberbaron (robr)Commented:
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

0
cmdolcetAuthor Commented:
I actually had to define a flag on the form entry/load and once the form was loaded I would change the flag state and this seems to work.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cmdolcetAuthor Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.