Objects and their attributes

brechtjah

Member
Joined
Mar 23, 2008
Messages
23
Programming Experience
Beginner
Hi I'm new here, I didn't really knew where to post this so I posted it here. I don't want to rush in but...
I have a question about something I'm programming in VB.NET right now. I'm trying to make my code smaller. What I have to do is change the attributes of several labels or textboxes.

Like for instance I have this:
Label1.visible = false
Label2.visible = false
Label3.visible = false
...
Label23.visible = false

I want to make it so I only have a few lines of code:
dim intCount as integer
for intCount = 0 to 23
Label <intCount>.visible = false
next

that would make my code much better/smaller, and smaller means more synoptic. The intCount would just get replaced somehow, that's what I want...

Thanks
 
The Controls collection of each container can access an item by the string name of the control. Me.Controls("controlname")
 
I tried this piece of code, but it didn't work however. Maybe I'm doing something wrong. A quick explain: I want to order labels depending on the current hour. If the hour is 13, label13 will come in first then all the rest. The little peace of code was just to test it out. Anyway, my objects just don't appear on the form. Is there some way in which this would not work or am I doing something wrong, am I not using the syntax as it should?

VB.NET:
    Private Sub LayoutCTRLTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LayoutCTRLTimer.Tick
        Dim intUur, intI, intYcoord As Integer
        intUur = TimeOfDay.Hour


        
        For intI = intUur To 2
            Me.Controls("lbl" & intI).Location = New Point(62, 84 + intYcoord)
            Me.Controls("lbl" & intI).Visible = True
            intYcoord = intYcoord + 26
        Next

    End Sub

Thanks
 
Last edited by a moderator:
"For x As Integer = 13 To 2" never happens, unless you Step -1.
 
Back
Top