Loop through labelx.text =

Posted on 2008-11-10
Last Modified: 2012-05-05
Is there a way to loop through labels to change the text value rather then

label1.text = "stuff1"
label2.text = "stuff2"

For x= 1 to 5
label(x).Text = "stuff" & x

or somthing
Question by:Rayzback
    LVL 8

    Accepted Solution

    Try something like

    Dim x as Integer = 0
    For Each lbl as Control In Me.Controls
    If TypeOf lbl Is Label Then
    lbl.Text = String.Format("stuff{0},x")
    x = x + 1
    End If

    Open in new window

    LVL 85

    Expert Comment

    by:Mike Tomlinson
    You've posted in multiple Zones...please clarify which ENVIRONMENT you are working  in as each has very different approaches to this type of problem.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now