Use a variable to refer to a control name in VB.NET?
Posted on 2003-03-16
I'm new to VB.NET and need to ask a fairly basic question:
In VB6, I could use a variable or combination of literals and variables to refer to a control on a form. For example, if I had a variable called intNumber and controls named "lbl10", "lbl11", "lbl12", etc, I could use the following code to refer to a control, and gain access to all of its methods and properties:
Me("lbl" & intNumber).Text = "new text"
I cannot find how to do this in VB.NET. When I attempt to use the above syntax, it gives me some error about being unable to index an object without a default property, or about not being able to implicitly convert a string to an integer.
Can you still use my variable + text method to refer to a control? or do I have to know the control's index number in order to refer to it? Is there a better method altogether to refer to a control without being able to "hard code" its control name?
Please help! Thank you :-)