Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cleaning Up Code With Many Similar Controls

Status
Not open for further replies.

edbytes

Programmer
Aug 29, 2001
27
0
0
US
What I would like to do is use a loop to change the value of many instances of the same controls.

The control is a combo box class used many times on the same form. I would like to take the following:

oForm = ThisForm.Pageframe1.Page2

oForm.cboAbcspecs1.Enabled = .T.
oForm.cboAbcspecs2.Enabled = .T.
oForm.cboAbcspecs3.Enabled = .T.
oForm.cboAbcspecs4.Enabled = .T.
oForm.cboAbcspecs5.Enabled = .T.


to something along the lines of:


for i=1 TO 5
("oForm.cboAbcSpecs"+ALLTRIM(STR(i))+".Enabled") = .t.
endfor


I have tried a couple of variations of the loop like storing to a variable and macro substitution but I'm still missing somehting. This would eliminate a large amount of repetitive code and would be greatly appreciated.
 
try this:

for i=1 TO 5
oCombo = "oForm.cboAbcSpecs"+ALLTRIM(STR(i))+".Enabled"
&ocombo = .T.
endfor

 
Thanks. I did similar but didn't get it. Thanks again.
 
OR you could also use

ThisForm.Pageframe1.Page2.setall("enabled",.t.,"<<combo box class name>>")
 

You can use all of them, WITH...ENDWITH, FOR...ENDFOR, and macrosubstitution, all at once.

Here is a working piece from my code, you can adjust it:

Code:
WITH ThisForm
   .txtMmYy1.Value = LEFT(mmyy, 2)+"/"+RIGHT(mmyy, 2)

   FOR i=1 TO 6
      ii=STR(i,1)

      .lblHol&ii..Enabled = IIF(hol(i)#{}, .T., .F.)
      .txtHol&ii..Enabled = IIF(hol(i)#{}, .T., .F.)

      WITH   .Optiongroup&ii
         .Option1.Enabled      = IIF(hol(i)#{}, .T., .F.)
         .Option2.Enabled      = IIF(hol(i)#{}, .T., .F.)
         .Option1.MousePointer = IIF(hol(i)#{}, 99, 0)
         .Option2.MousePointer = IIF(hol(i)#{}, 99, 0)
         .Option1.MouseIcon    = IIF(hol(i)#{}, pointer, '')
         .Option2.MouseIcon    = IIF(hol(i)#{}, pointer, '')
      ENDWITH
   NEXT
ENDWITH

Your code might look something like this (not tested):

Code:
WITH ThisForm
   FOR i=1 TO 5
      ii=STR(i,1)
      .cboAbcSpecs&ii..Enabled = .T.
   ENDFOR
ENDWITH
 
works for me. I created a form, put 4 comboboxes on it, put a command button. In the command button click put the following:

For x = 1 To 4
cname = "thisform.combo"+Transform(x)+".enabled"
&cname = .F.
Endfor
Thisform.Refresh

when clicked ALL comboboxes were disabled...

Are you doing a page2 refresh?
 
As you can see, there are lots of different approaches. Here's another ....

Just another reason to love and support this site/forum. I spend alot of time just reading others problems and presented solutions. It has saved me alot of headaches.

Thanks to all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top