smurray
asked on
displaying labes on a form
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%
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%
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
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
You can do what you want only in VB6 bu using CallByName.
ASKER
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...
ASKER
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 ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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