Solved

Looping through objects

Posted on 2006-11-28
1
204 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expando 4 46
How Do I set the Visual Minor Grid Interval Value Programatically? 4 35
Iterate a dictionnary to change values 4 53
vb.net checkbox 7 41
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…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

912 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

20 Experts available now in Live!

Get 1:1 Help Now