Solved

Looping through objects

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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