C
Cerebrus99
Hi,
Say, I have 20 textboxes on my form placed in different panels, groupboxes.
The names of the textboxes range from "TextBox1" to "TextBox20".
I want to get a reference to each textbox using it's already known name, as
in :
-------------------------------------------------------
Dim i As Integer
For i = 1 To 20
Dim txt As TextBox = CType("Textbox" & i, TextBox)
^^^^^^^^^^
txt.Text = "Number " & i
Next
-------------------------------------------------------
But of course, the above code doesn't even compile, since a String cannot be
converted to a System.Windows.Forms.TextBox. Of course, I could use other
options(Such as For-each loops), but my main purpose is not that. (See
below)
So, my question actually is: How do I use a dynamically constructed string,
containing the name of an Object (or Control) to get a reference to the
Object itself ?
Regards,
Cerebrus.
Say, I have 20 textboxes on my form placed in different panels, groupboxes.
The names of the textboxes range from "TextBox1" to "TextBox20".
I want to get a reference to each textbox using it's already known name, as
in :
-------------------------------------------------------
Dim i As Integer
For i = 1 To 20
Dim txt As TextBox = CType("Textbox" & i, TextBox)
^^^^^^^^^^
txt.Text = "Number " & i
Next
-------------------------------------------------------
But of course, the above code doesn't even compile, since a String cannot be
converted to a System.Windows.Forms.TextBox. Of course, I could use other
options(Such as For-each loops), but my main purpose is not that. (See
below)
So, my question actually is: How do I use a dynamically constructed string,
containing the name of an Object (or Control) to get a reference to the
Object itself ?
Regards,
Cerebrus.