Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine Control Name Dynamically?

Status
Not open for further replies.

davidbeach

Electrical
Mar 13, 2003
9,483
Working on a project where I have multiple similarly named controls, Text Boxes in this case, where I want to build the control name in code and then assign the value.

For instance I have text boxes:
TB_A_1_1
TB_A_2_1
TB_A_1_2
TB_A_2_2

And I have the text that needs to go into those text boxes in a 2x2 string array. What I'd like to do is, within a set of loops, have one equation that would function as
TB_A_i_j.Text = Array(i,j)

Of course it doesn't seem to be that easy. Is there some way of doing this, or do I have to brute force it and have multiple IF statements (or other construct)?

Working in the VB portion of Visual Studio 2010.
 
Replies continue below

Recommended for you

How would one create an array of text boxes? I think it might be possible to define them in code, but is there anyway to set them up in design?
 
Well, that got me looking in the right direction. Apparently the copy and paste method of creating control arrays ended with VB6. In VB2010 (Visual Studio Express 2010) the method that I found that works is in each subroutine where I want to use an array of TB_A_x_x would be to start with
Code:
Dim TB_A as TextBox(,)={{TB_A_1_1,TB_A_1_2},{TB_A_2_1,TB_A_2_2}}

Then I can use a pair of indices to control which text box I want. Too bad VB2010 doesn't have an OPTION BASE 1 option.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor