Resolved If RadioButton1.Checked = True Statement Is Ignored Within TextChanged Event

zunebuggy65

Active member
Joined
Oct 12, 2023
Messages
42
Programming Experience
3-5
So I have 6 radio buttons and a textbox and this event:

VB.NET:
    Private Sub txtBox1_TextChanged(sender As Object, e As EventArgs) Handles txtBox1.TextChanged
        If rdoButton1.Checked = True Then
            If txtBox1.Text <> "" Then
                If txtBox3.Text <> "" Then
                    'do some stuff
                Else
                    'do some stuff
                End If
            Else
                'do some stuff
            End If
        End If
    Exit Sub

Visual Studio does not report any errors and I did an output of rdoButton1.Checked and it is indeed True, but the "rdoButton1.Checked = True" condition is ignored as well as all If Thens nested within.

If I remove that rdoButton1.Checked and just have the test of it like below, it works fine. I have 6 radio buttons and they all share this txtBox1 but selecting the various radio buttons changes the functionality of the textbox.

VB.NET:
    Private Sub txtBox1_TextChanged(sender As Object, e As EventArgs) Handles txtBox1.TextChanged
        If txtBox1.Text <> "" Then
                If txtBox3.Text <> "" Then
                    'do some stuff
                Else
                    'do some stuff
                End If
         Else
                'do some stuff
         End If
    Exit Sub

I really just need a way that if a user changes any text in the textbox that it will check the radio button selected and based on that will do something else.

Thank you.
 
I approached this differently and I think I got it working:

Inside the
VB.NET:
Private Sub txtBox1_TextChanged(sender As Object, e As EventArgs) Handles txtBox1.TextChanged
event I put if
VB.NET:
If rdoButton1.Checked = True Then
and I created a custom Function to look at the text from the textbox which contains a header.

VB.NET:
    Private Function DecodeHeader(myHeader As String, ByRef myFirst As String, ByRef myDecVal As Integer) As Boolean
        DecodeHeader = False
        If Len(myHeader) <> 32 Then
            DecodeHeader = False
        Else
            If myHeader.Substring(0, 23) = "some specific text here" Then
                myFirst = myHeader.Substring(24, 6)
                myDecVal = CInt("&H" & myHeader.Substring(30, 2))
                DecodeHeader = True
            End If
        End If
    End Function

Then is DecodeHeader(myHeader, myFirst, myDecVal) = True then 'do something

This seems to work OK but I am fairly new at passing variables to a formula and returning a Boolean.

I have no idea why it didn't work before.
 
The only thing I would have suggested is to debug and step-through your code to see what the value of each control is at the time the code runs.
In a vacuum of just seeing the code snippet, to me, that should have worked just fine.
 
Back
Top