Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42225

Help condensing repetative code

$
0
0
I had 2 questions, I need to Gray out 48 text boxes on Run of the program. And keep them grayed unless the user makes a selection to enter their own criteria via a selection within a ComboBox.

My first question, and I hope by the text below you can make sense of how repetitive this is going to become and what it is I'm trying to do. I will have to write the If Statements over and over and was wondering if I could condense these since the code will be so repetitive.

Also The Read only statements in class level of the Form_Load, is there anyway to condense these other than putting them all in a function to call on? Since I will have to write ReadOnly statements for 48 TextBoxes.

Code:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtQuadEx.ReadOnly = True
        txtQuadReps.ReadOnly = True
        txtQuadSets.ReadOnly = True

        txtUniQuadEx.ReadOnly = True
        txtUniQdReps.ReadOnly = True
        txtUniQdSets.ReadOnly = True

    End Sub

    Private Sub cboQuadEx_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboQuadEx.SelectedIndexChanged
        If cboQuadEx.Text = "Enter My Own Exercise" Then
            txtQuadEx.ReadOnly = False
        Else
            txtQuadEx.ReadOnly = True
        End If

    End Sub


    Private Sub cboQuadReps_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboQuadReps.SelectedIndexChanged
        If cboQuadReps.Text = "Enter My Own Reps/Sets" Then
            txtQuadReps.ReadOnly = False
            txtQuadSets.ReadOnly = False

        Else
            txtQuadReps.ReadOnly = True
            txtQuadSets.ReadOnly = True

        End If

    End Sub

    Private Sub cboUniQuadEx_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboUniQuadEx.SelectedIndexChanged
        If cboUniQuadEx.Text = "Enter My Own Exercise" Then
            txtUniQuadEx.ReadOnly = False
        Else
            txtUniQuadEx.ReadOnly = True
        End If

    End Sub

    Private Sub cboUniQuadReps_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboUniQuadReps.SelectedIndexChanged
        If cboUniQuadReps.Text = "Enter My Own Reps/Sets" Then
            txtUniQdReps.ReadOnly = False
            txtUniQdSets.ReadOnly = False

        Else
            txtUniQdReps.ReadOnly = True
            txtUniQdSets.ReadOnly = True

        End If
    End Sub


Viewing all articles
Browse latest Browse all 42225

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>