Solved

# Variable label name

Posted on 2003-10-30
Medium Priority
201 Views
I am attempting to display an array by using labels.  However, I need to be able to use a variable within the label name to know what to display.

For example:

For i = 1 to intNumNodes
ToNode(i) = intValue
Next i

lblNode(i).caption = intValue     <---------- This is the problem

I have labels named lblNode1, lblNode2, etc.

I appreciate any helped provided.

Thanks,
Jeff

0
Question by:bowen18
[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
• 4
• 3
• 3

LVL 48

Expert Comment

ID: 9651024
What type is IntValue?
0

LVL 48

Expert Comment

ID: 9651067
For i = 1 to intNumNodes
ToNode(i) = intValue
Next i
for i = 1 to Innumnodes
lblNode(i).caption = intValue
next i
0

LVL 48

Expert Comment

ID: 9651069
For i = 1 to intNumNodes
ToNode(i) = intValue
Next i

for i = 0 to Innumnodes - 1
lblNode(i).caption = intValue
next i
0

LVL 2

Author Comment

ID: 9651100
IntValue is an integer.  However, the problem is with the lblNode(i).caption line.  VB doesn't accept that as a valid label name.  Is there some way to include the varible i within the label name?
0

LVL 16

Accepted Solution

Richie_Simonetti earned 2000 total points
ID: 9651106
You could use an array of labels!! matching some like this:

For i = 1 to intNumNodes
lblNode(i).caption  = ToNode(i)
Next i

Or see CallByname function in MSDN Help.
0

LVL 48

Expert Comment

ID: 9651159
Are yo using .NET ?? if so
try lblnode.Text = whatever
0

LVL 2

Author Comment

ID: 9651170
Using version 6.
0

LVL 16

Expert Comment

ID: 9651193
Well, it appears to be a "two-way only" thread so, good luck!.
Cheers
0

LVL 2

Author Comment

ID: 9651215
-Richie_Simonetti

Thanks I'm using your suggestion with the label array.  Never used it before, but makes perfect sense in this case.

Thanks,
Jeff
0

LVL 16

Expert Comment

ID: 9651282
Array of controls use less resources than using label1, label2, label3 and so on.
You could use array of each vb intrinsic controls and almost all ocx.
Cheers ... again.
0

## Featured Post

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asseâ€¦
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describesâ€¦
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can launâ€¦
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This lâ€¦
###### Suggested Courses
Course of the Month11 days, 6 hours left to enroll