Solved

Looping through objects

Posted on 2006-11-28
1
194 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
Comment Utility
       Dim i As Integer

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

14 Experts available now in Live!

Get 1:1 Help Now