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
gbnortonAsked:
Who is Participating?
 
Jacques Bourgeois (James Burger)PresidentCommented:
Controls("lblBox" & strBox1Position).text = "X"
0
 
rawinnlnx9Commented:
It's all case sensitive.

I'm fairly sure if you do this in vb it's:

lblBox1.Text = "1"
0
 
rawinnlnx9Commented:
You should read all of this: http://www.vbtutor.net/lesson3.html
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
gbnortonAuthor Commented:
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
0
 
rawinnlnx9Commented:
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

Open in new window

0
 
ArkCommented:
strictly speaking
Container.Controls("lblBox" & strBox1Position).text = "X"
0
 
gbnortonAuthor Commented:
Prefect!  Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.