gbnorton
asked on
Visual Basic 2012 code to reference text box with variable
I need to end up with this:
lblBox1.text = "X"
This is my attempt:
strBox1Position = "1"
("lblBox" & strBox1Position).text = "X"
I'm getting "syntax error"
Thanks,
Brooks
lblBox1.text = "X"
This is my attempt:
strBox1Position = "1"
("lblBox" & strBox1Position).text = "X"
I'm getting "syntax error"
Thanks,
Brooks
You should read all of this: http://www.vbtutor.net/lesson3.html
ASKER
I see I poorly described by problem. I want to select a control by concatenating its root name with a suffix.
lblBox1.text
lblBox2.text
lblBox3.text
...
This way I can cycle through my controls and change them.
for i = 1 to 10
"lblBox" & Cstr(i).text = "X"
next
lblBox1.text
lblBox2.text
lblBox3.text
...
This way I can cycle through my controls and change them.
for i = 1 to 10
"lblBox" & Cstr(i).text = "X"
next
Dim cnt As Integer = 1
For Each control As Control In Controls
If TypeOf control Is Label Then
If control.Name = "lblBox" & cnt.ToString() Then
control.Text = "X"
cnt += 1
End If
End If
Next control
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
strictly speaking
Container.Controls("lblBox " & strBox1Position).text = "X"
Container.Controls("lblBox
ASKER
Prefect! Thanks!
I'm fairly sure if you do this in vb it's:
lblBox1.Text = "1"