Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Looping through objects

Posted on 2006-11-28
1
Medium Priority
?
240 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 1000 total points
ID: 18027627
       Dim i As Integer

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

604 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