Thursday, September 20, 2012 6:25 AM
hi, i have a program, that has some code something like this....
If varb = 1 Then TextBox1.Text = vara If varb = 2 Then TextBox2.Text = vara If varb = 3 Then TextBox3.Text = vara If varb = 4 Then TextBox4.Text = vara
my question is, if i wanted to do this 180 times, is there a way to put this in code with a variable that counts from 1 to 180 and just use 1 line of code? thanks....
Thursday, September 20, 2012 8:00 AM
Try thisDim varb As Integer = 1
Dim mycontrol() As Control = Me.Controls.Find("Textbox" & varb, True)
mycontrol(0).Text = "abc"
Thursday, September 20, 2012 10:03 AM
For i As Integer = 1 To 180 If varb = i Then Controls.Find("TextBox" & Cstr(i),True)(0).Text = vara End If Next
- Marked As Answer by Mark Liu-lxfModerator Thursday, September 27, 2012 8:08 AM
Thursday, September 20, 2012 10:48 AM
Since it is likely that number of textboxes would be created in code, not in the designer, then you should create an array or list of the textboxes as you create them. Then you can simply update the textbox using the variable as the index:
Textboxes(varb).Text = vara
Thursday, September 20, 2012 4:41 PMthanks guys, very helpful....
Thursday, September 20, 2012 6:39 PM
thanks guys, very helpful....
Please mark as answers the posts that solve your issue, beside to vote as helpful for helpful posts.