Results 1 to 9 of 9

Thread: Help condensing repetative code

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    11

    Help condensing repetative code

    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
    Last edited by Graffix; May 15th, 2013 at 09:01 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width