Concatenating Variables In Loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • doma23
    New Member
    • May 2010
    • 107

    #1

    Concatenating Variables In Loop

    I have this code:

    Code:
    For COUNT = 1 To 5
        EmptyFields_Period [COUNT] = True
        For Each ctl In Form_frmMain.Controls
            If ctl.ControlType = acTextBox Then
                If ctl.Tag = "Period" & COUNT Then
                    If ctl <> "" Then
                        EmptyFields_Period [COUNT] = False
                    End If
                End If
            End If
        Next ctl
    Next COUNT
    What I'm trying to do is to set the boolean variables from EmptyFields_Per iod1 to EmptyFields_Per iod5 to TRUE at the beginning of the loop and then if certain conditions are met set it to FALSE, but posted code is clearly not a good syntax.
    Tnx.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by doma23
    I have this code:

    Code:
    For COUNT = 1 To 5
        EmptyFields_Period [COUNT] = True
        For Each ctl In Form_frmMain.Controls
            If ctl.ControlType = acTextBox Then
                If ctl.Tag = "Period" & COUNT Then
                    If ctl <> "" Then
                        EmptyFields_Period [COUNT] = False
                    End If
                End If
            End If
        Next ctl
    Next COUNT
    What I'm trying to do is to set the boolean variables from EmptyFields_Per iod1 to EmptyFields_Per iod5 to TRUE at the beginning of the loop and then if certain conditions are met set it to FALSE, but posted code is clearly not a good syntax.
    Tnx.
    Try:
    Code:
    'Initialize to True?
    EmptyFields_Period1 = True
    EmptyFields_Period2 = True
    EmptyFields_Period3 = True
    EmptyFields_Period4 = True
    EmptyFields_Period5 = True
    
    For Count = 1 To 5
      For Each ctl In Form_frmMain.Controls
        If ctl.ControlType = acTextBox Then
          If ctl.Tag = "Period" & Count Then
            If ctl <> "" Then
              Select Case Count
                Case 1
                  EmptyFields_Period1 = False
                Case 2
                  EmptyFields_Period2 = False
                Case 3
                  EmptyFields_Period3 = False
                Case 4
                  EmptyFields_Period4 = False
                Case 5
                  EmptyFields_Period5 = False
              End Select
            End If
          End If
        End If
      Next ctl
    Next Count

    Comment

    • doma23
      New Member
      • May 2010
      • 107

      #3
      Ok, I was thinking about setting the variables to true before the loop, but then I still didn't know how would I change them to false inside the loop. Clearly, SELECT CASE is obvious solution that didn't come to my mind. Thank you! This solves my problem.

      Just for the sake of knowing - what if there is 100 variables that need to be changed? Could it be done in some efficient way or would I need to use SELECT CASE 100 times?

      BTW. I've read recently couple of your posts where you and Stewart were explaining how randomizer function really works. I was impressed by the knowledge, as well as by the collaboration with Stewart. It looked like synchronized swimming. :) Nice to 'officially' meet you. Cheers! :)

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by doma23
        Ok, I was thinking about setting the variables to true before the loop, but then I still didn't know how would I change them to false inside the loop. Clearly, SELECT CASE is obvious solution that didn't come to my mind. Thank you!
        This solves my problem.

        But, I would like to know, what if there is 100 variables that need to be changed? Could it be done in some efficient way or would I need to use SELECT CASE 100 times?
        Tnx!

        BTW. I've read recently couple of your posts where you and Stewart were explaining how randomizer function really works. I was impressed by the knowledge, as well as by the collaboration with Stewart. It looked like synchronized swimming. :) Nice to 'officially' meet you. Cheers! :)
        The pleasure is all ours!

        Comment

        Working...