|
-
Aug 30th, 2008, 11:27 AM
#1
Thread Starter
Junior Member
[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.
-
Aug 30th, 2008, 11:31 AM
#2
Re: how to use label(x).text with 2008
vb Code:
me.controls("label" & x.tostring).text ="hello"
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 30th, 2008, 11:32 AM
#3
Re: how to use label(x).text with 2008
Code:
x=2
Me.Controls("label" & x.ToString()).Text = "hello"
-
Aug 30th, 2008, 11:32 AM
#4
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 30th, 2008, 11:35 AM
#5
Thread Starter
Junior Member
Re: how to use label(x).text with 2008
Thanks for answering so quick.
-
Aug 30th, 2008, 11:45 AM
#6
Lively Member
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.
whats the benefit of beeing rated?

-
Aug 30th, 2008, 11:48 AM
#7
Re: [RESOLVED] how to use label(x).text with 2008
Well thats another discussion which has been beaten to death 
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 30th, 2008, 12:15 PM
#8
Lively Member
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).
whats the benefit of beeing rated?

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|