Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 149
  • Last Modified:

changing multiple controls with a single line of code


Hello,

Say I have the following controls on a form:

textbox1
textbox2
textbox3
textbox4

Whats is the most efficient way to set the enable value to false ?
0
andyw27
Asked:
andyw27
1 Solution
 
Patrick MatthewsCommented:
Hi andyw27,

You could do something like:

Dim Counter As Long

For Counter = 1 To 4
    Controls("textbox" & Counter).Enabled = False
Next

Hardly seems worth it for four controls; pretty handy when there are a dozen...

Regards,

Patrick
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Put all 4 textboxes onto 1 frame, and change the frame's enabled property to false

another option is to create a control array of the 4 textboxes, each having the same name but a different index value.
you can then loop through (assuming you name the control textbox with index values from 0 to 3):

dim l as long
for l = textbox.lbound to textbox.ubound
 textbox(l).enabled = false
next
0
 
andyw27Author Commented:

how do you refer to the collective in a control array?

for example text1(0) refers to the first one, is there a way (other than some kind of loop) to influence all members of the control array?
0
 
pradapkumarCommented:
Its not possible in single line and without using loop to change all the control's property.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now