Solved

Looping through objects

Posted on 2006-11-28
1
231 Views
Last Modified: 2010-05-18
Hello,

I have, say, 10 labels, named Label1, Label2, ... Label10. What I want to do, in terms of pseudocode is to perform such a loop, where X is a value between 1 and 10:

For i = 1 to 10
  If i < X Then
    LabelX.Text = "Yes"
  Else
    LabelX.Text = "No"
  End If
Next

In order to translate the LabelX part to valid code, the first method I decided to use was to do it like:

Execute ("Label" & X & ".Text = ""Yes""")

However, Execute is not available in VB (it is in VBS and ASP.) The other method is to loop through Me.Controls as described here (http:Q_21036782.html). Or perhaps creating an array of the Labels could be an alternative, but an array does not contain the Labels byref, or at least I don't know how to make it do. (The benefit was I didn't have to go through ALL the controls available to only find those 10 Labels.)

What is your opinion?
0
Comment
Question by:huji
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 48

Accepted Solution

by:
AlexFM earned 250 total points
ID: 18027627
       Dim i As Integer

        For i = 1 To 10
            Me.Controls("Label" & i.ToString).Text = "Test"
        Next
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

728 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