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
Solved

displaying labes on a form

Posted on 1999-01-22
6
152 Views
Last Modified: 2010-05-03
Is there a way of displaying label that are labeled as
label1(0) to label1(5) then label2(0) through label2(5)
that is embeded in a loop like such.

Dim I%
Dim J%

Dim Command$
For J% = 0 To 5
For I% = 6 To 11
     
Command$ = "what ever" + Format$(I%) '& Chr(13)
'Will generate "User1" to "User60"
DoEvents
Label(Format(J%) & (Format$(I%))).Visible = True      

Next I%
Next J%
0
Comment
Question by:smurray
6 Comments
 
LVL 12

Expert Comment

by:mark2150
ID: 1470201
No, there is no way to use a variable for the object name.

You can dynamically compute the index of a control array, but the name of the control itself needs to be given. How could it compile otherwise?

There are other tricks you can do. What exactly are you trying to accomplish?

M

0
 
LVL 1

Expert Comment

by:natek012299
ID: 1470202
Yah, from what I can tell is that you want to create a control array.
We'll talk about creating one control array and you can create 2 or more after one of course!

Okay, I want to be able to dynamically add labels to my form.Create a leble, we'll set its name property to lblTest. The next step is important. Set the index property of the lblTest control to 0. So, we now have the first control in the lblTest() control arrayed as lblTest(0). Now in the form_load event I would simply write this code to create a dynamic number of labels based on a constant or whatever.

Form_Load()
Const NumofLables = 5
Dim x as integer

for x = 1 to NumOfLabels
    'the load statement is used to create a new instance of a    'control in this case a control array.    
    load lblTest(x)
'you have to make the control visible    
lblTest(x).visible = true
'set its caption
    lblTest(x).caption = x
'and position the control
    lblTest(x).top = lblTest(x - 1).height
next
end sub

whalla, I now have six labels created on the fly or dynamically.
Hope this helps.
Nate
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 1470203
You can do what you want only in VB6 bu using CallByName.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:smurray
ID: 1470204
I am currently using vb5 but I just picked up vb6 how would I go about using this emoreua? Also do you know of any good info regarding network programming. More points will follow...
0
 

Author Comment

by:smurray
ID: 1470205
I need to have labes appear from label(0) to label(5) with 6 labels uder each. Like Label(0)(0) label (0)(1) and so on. Is it possible ?
0
 
LVL 12

Accepted Solution

by:
mark2150 earned 30 total points
ID: 1470206
Why not have just *one* label array and use, 0-5 as group #1, 6-11 as group #2, etc. This is *possible* to code where as having the control name as a variable is *NOT*.

M

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

792 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