By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,567 Members | 1,522 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,567 IT Pros & Developers. It's quick & easy.

Concatenating Variables In Loop

doma23
100+
P: 107
I have this code:

Expand|Select|Wrap|Line Numbers
  1. For COUNT = 1 To 5
  2.     EmptyFields_Period [COUNT] = True
  3.     For Each ctl In Form_frmMain.Controls
  4.         If ctl.ControlType = acTextBox Then
  5.             If ctl.Tag = "Period" & COUNT Then
  6.                 If ctl <> "" Then
  7.                     EmptyFields_Period [COUNT] = False
  8.                 End If
  9.             End If
  10.         End If
  11.     Next ctl
  12. Next COUNT
What I'm trying to do is to set the boolean variables from EmptyFields_Period1 to EmptyFields_Period5 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.
Jul 29 '10 #1

✓ answered by ADezii

@doma23
Try:
Expand|Select|Wrap|Line Numbers
  1. 'Initialize to True?
  2. EmptyFields_Period1 = True
  3. EmptyFields_Period2 = True
  4. EmptyFields_Period3 = True
  5. EmptyFields_Period4 = True
  6. EmptyFields_Period5 = True
  7.  
  8. For Count = 1 To 5
  9.   For Each ctl In Form_frmMain.Controls
  10.     If ctl.ControlType = acTextBox Then
  11.       If ctl.Tag = "Period" & Count Then
  12.         If ctl <> "" Then
  13.           Select Case Count
  14.             Case 1
  15.               EmptyFields_Period1 = False
  16.             Case 2
  17.               EmptyFields_Period2 = False
  18.             Case 3
  19.               EmptyFields_Period3 = False
  20.             Case 4
  21.               EmptyFields_Period4 = False
  22.             Case 5
  23.               EmptyFields_Period5 = False
  24.           End Select
  25.         End If
  26.       End If
  27.     End If
  28.   Next ctl
  29. Next Count

Share this Question
Share on Google+
3 Replies


ADezii
Expert 5K+
P: 8,701
@doma23
Try:
Expand|Select|Wrap|Line Numbers
  1. 'Initialize to True?
  2. EmptyFields_Period1 = True
  3. EmptyFields_Period2 = True
  4. EmptyFields_Period3 = True
  5. EmptyFields_Period4 = True
  6. EmptyFields_Period5 = True
  7.  
  8. For Count = 1 To 5
  9.   For Each ctl In Form_frmMain.Controls
  10.     If ctl.ControlType = acTextBox Then
  11.       If ctl.Tag = "Period" & Count Then
  12.         If ctl <> "" Then
  13.           Select Case Count
  14.             Case 1
  15.               EmptyFields_Period1 = False
  16.             Case 2
  17.               EmptyFields_Period2 = False
  18.             Case 3
  19.               EmptyFields_Period3 = False
  20.             Case 4
  21.               EmptyFields_Period4 = False
  22.             Case 5
  23.               EmptyFields_Period5 = False
  24.           End Select
  25.         End If
  26.       End If
  27.     End If
  28.   Next ctl
  29. Next Count
Jul 29 '10 #2

doma23
100+
P: 107
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! :)
Jul 29 '10 #3

ADezii
Expert 5K+
P: 8,701
@doma23
The pleasure is all ours!
Jul 29 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.