[RESOLVED] how to use label(x).text with 2008
I want to change text on certain labels, eg
label2.text
label7.text
what is the syntax to use variable x instead of number in label name
something like-
x=2
label(x).text="hello"
x=7
label(x).text="hello"
I know this does not work, but cant find right way to do it.
Thanks in advance.
Re: how to use label(x).text with 2008
vb Code:
me.controls("label" & x.tostring).text ="hello"
Re: how to use label(x).text with 2008
Code:
x=2
Me.Controls("label" & x.ToString()).Text = "hello"
Re: how to use label(x).text with 2008
There are no control arrays in .NET. You can do other things like create an array and add your controls to it and loop through it. You can use the forms controls collection and check the type of control to filter out he controls not being updated. Or you can also search the Forums for other solutions/variations :)
Re: how to use label(x).text with 2008
Thanks for answering so quick.
Re: [RESOLVED] how to use label(x).text with 2008
extending RobDog888's Post with a sample:
Code:
For each Ctl as Label in new Label(){Label1, Label2, Label3}
Ctl.Text="Hallo"
next
Thats a better practice than access Controls by their Name-Property.
Because the Name-Property may be changed.
Furthermore it's nogood practice not to name Controls explicitely, and leave them as the IDE did generate (Label1, Label2, Label3).
Especially if there are more than one Control, especially especially if they are accessed by Code (a tumb, never-changed Caption needs not to be named explicitely).
Every Control should be named "speaking", like "blStart", "lbEnd" to make clear for what they are used for.
Re: [RESOLVED] how to use label(x).text with 2008
Well thats another discussion which has been beaten to death :D
Using humgarian notation in .NET is useless since ther are so many controls you can not easily manage the prefixes like you could in VB6. Plus .NET can handle long object names better then VB6 so you can have "MySuperDuperUserControlThatIsntNamedWithHungarianNotation" or such :D
Re: [RESOLVED] how to use label(x).text with 2008
Ok, the way u name the controls maybe that beaten discussion. But that they have to be named explicitely (according to any convention) - thats not to discuss (i think).