6 Years
Discussion Span
Last Post by codeorder

See if this helps.

'// Prerequisites: 3 Buttons
        Dim myCoolControls() As Control = {Button1, Button2, Button3}
        For Each onlyCoolControl As Control In myCoolControls : onlyCoolControl.BackColor = Color.SteelBlue : Next
I got you dude.

Neither of these appear to work for what I want to do, which is dynamically change text within large groups of labels as my program runs.

What if I've got a list of 10 labels that contain names, and circumstances come up where I'd want to change the name in Label5, say..., or labels 1, 3, and 7 based on some decision in the program?


F*cking Microsoft with their change for the sake of change. Removing control arrays? Really? That's what they call an improvement? They never fail to disappoint me.


Edited by Paul G: n/a


Here, I hope this helps.

Public Class Form1
    Dim myLabels(10) As Label
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        myLabels(1) = Label1
        myLabels(2) = Label2
        myLabels(3) = Label3
        myLabels(4) = Label4
        myLabels(5) = Label5
        myLabels(6) = Label6
        myLabels(7) = Label7
        myLabels(8) = Label8
        myLabels(9) = Label9
        myLabels(10) = Label10
    End Sub

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        myLabels(3).Text = "Hello World"
    End Sub
End Class
'// Pre-requisites: 3 Labels
        Dim myCoolControls() As Control = {Label1, Label2, Label3}
        '// since Arrays are Index based, Index 0 being Label1, this will change Label2's text.
        myCoolControls(1).Text = "Look, it works!  I like Microsoft afterall."
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.