Yes a control array, but this no longer exists ?? What do you mean under controls, have you an example ?
Of course a control array exists:
Dim boxes(0 to 1) as TextBox
boxes(0) = TextBox1
boxes(1) = TextBox2
the difference is you now have to make the control array yourself..
-
If the concept of Hashtables is new to you ,you should read up about them. They are a powerful data storage container, but there is a better one, which hashtable is based on
If you take a look at System.Colelctions.Generics.Dictionary you will see it is broadly the same as a hashtable, except you can specify what ytpes of objects you wish to put in it.
By default, a Hashtable uses String for the key and Object for the data. This is fine, but you have to cast the object back into the specific type you put in. Dictionary on the other hand can be typed when you make it:
Dim textboxes as New Dictionary(Of String, Textbox)
Now, you can store your textboxes into the dictionary, with strings for lookups:
textboxes.Add("day1period1", tbxD1P1)
textboxes.Add("day1period2", tbxD1P2)
textboxes.Add("day1period3", tbxD1P3)
when you say:
textboxes.Item("day1period1")
it behaves like a textbox, because it IS a textbox, so you can:
textboxes.Item("day1period1").Text = "this is the text in tbxD1P1"
This is very similar to what youre asking with:
Txt(a).Text = "hello"
-
If you were doing this with a hashtable, as per what vis781 has shown you, you would do this:
DirectCast(textBoxesHT.Item("day1period1"), TextBox).Text = "this is the text in tD1P1"
it looks similar to the dictionary, with the addition of
DirectCast(object to cast, type to cast into)
we can avoid needing to write that, by using a typed dictionary
.
-
Note also we could have done this with a regular array as it has a fixed size. suppose there are 5 days in the week and 10 perioods in the day:
Dim theWeek(1 to 5, 1 to 10) as TextBox
'note we have to link our text boxes on the form into this array
theWeek(1,1) = tbxD1P1
theWeek(1,2) = tbxD1P2
theWeek(1,3) = tbxD1P3
-
finally, i must ask why youre doing this with ~50 text boxes.. did you not see the datagridview control? it allows you to work with a grid of editable cells (that are, in essence textboxes), like in an excel spreadsheet and is much easier than all this messing around with big blocks of text boxes...