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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is it possible to code multiple objects invisible other than this 3

Status
Not open for further replies.

kiwieur

Technical User
Apr 25, 2006
200
GB
Hi,

I have 15 labels that are set to be invisble at form load and i was wondering if there is a neater way to code it than the example below

Code:
Box1.Visible = False
    Box2.Visible = False
    Box3.Visible = False
    Box4.Visible = False
    Box5.Visible = False
    Box6.Visible = False
    Box7.Visible = False
    Box8.Visible = False
    Box9.Visible = False
    Box10.Visible = False
    Box11.Visible = False
    Box12.Visible = False
    Box13.Visible = False
    Box14.Visible = False
    Box15.Visible = False
    Box16.Visible = False

Regards

Paul
 
You can do this (typed, not tested):

[tt]For i=2 to 16
Me("Box" & i).Visible=False
Next i[/tt]
 
How are ya kiwieur . . .
[ol][li]Put a question mark ([purple]?[/purple]) in the [blue]Tag[/blue] property of the labels of interest.[/li]
[li]Then in the [blue]On Load[/blue] event of the form, copy paste the following:
Code:
[blue]   Dim ctl As Control
   
   For Each ctl In Me.Controls
      If ctl.Tag = "[purple][b]?[/b][/purple]" Then ctl.Visible = False
   Next[/blue]
[/li][/ol]
[blue]Done! . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
and just for the sake of putting my 2¢ in,
or maybe adding some insight...

Dim ctl As Control

For Each ctl In Me.Controls
If ctl.controlType = acLabel Then
If Left(ctl.Name,3) = "box" Then
ctl.Visible = False
End If
End If
Next

I think you may find Remou's the most succinct & efficient.
But it's always good to be aware of the controls collection,
and its properties for possibly, a more dynamic approach.

...have we covered all the bases yet?
 
Howdy Zion7 . . .

For what its worth if you take a good look [blue]my code is not [purple]dependent[/purple] on the label name! . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Hello SkipVought
The first box is numbered Box2, so i=2. Yes no? :)
 
Yes AceMan, I noticed but I'm under the impression though,
since your code & mine iterates through the
whole controls collection, and 'sinks' where
necessary, it would take longer than Remou's,
which is more explicit.

and, since your code is dependant on the Tag property,
I regarded it as requiring, "more "coding".

But i only brought that point up, in case
kiwieur was confused by now.


AceMan, I may be wrong about assuming Remou's
code is faster than yours & mine.
...and more succinct?

You would probably know better than me,
if that is the case....
Thx!
 
Zion7 . . .

Just throwing in a monkey wrench for fun . . . what happens if [blue]kiwieur[/blue] changes their mind and instead wants to hide 1,3,4,5.10,11,14,16?

Calvin.gif
See Ya! . . . . . .
 
This is a good thread. 3 different ways to tackle the same problem. Good info, whatever kiwieur chooses.
 
AceMan since you asked, "my" approach might be,

Dim varrBoxes As Variant
Dim x as integer

varrBoxes = Array(1,3,4,5,10,11,14,16)

For x = 0 To Ubound(varrBoxes)
Me("Box" & varrBoxes(x)).Visible=False
Next

...of course, each of our code can be modified accordingly.
yours would simply require changing the tag property,
which in retrospect, is probably the most flexible,
and probably now, the more succinct.(show off!)
 
Wow,

I never realised when i asked the question that it would attract so much interest, I would like to thank all contributors for their answers.

I think "stars" all round

Regards

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top