They don't have "name variables" because they are created at run time (when your app is executing) rather than at compile time - so the only time anyone knows how many of them there are is long after all the variable names have been assigned.
So you can't later access them "by name" as that code needs to know now many there are when you compile it!
That's not a major problem though, as you don't need to know the name of something to access it: if you have a Children class, and you create a Family as an array:
Dim Joe As Child = New Child()
Joe.name = "Joe"
Dim Sarah As Child = New Child()
Sarah.name = "Sarah"
Dim Pete As Child = New Child()
Pete.name = "Pete"
Dim family As List(Of Child) = New List(Of Child)()
family.Add(Joe)
family.Add(Sarah)
family.Add(Pete)
Then you could access the girl via her name:
Console.WriteLine(Sarah.name)
Or by accessing the Family:
Console.WriteLine(family(1))
With an array of Controls, you can do the same thing:
For Each ctrl As Control In Me.GB_Table.Controls
If TypeOf ctrl Is Button Then
...
End If
Console.WriteLine(ctrl.Text)
Next
Make sense?
Quote:
Interesting, and I'll try several strategies here.
The concept of 'Child' would seem that it needs to be done at coding time BUT the first sentence 'They don't have "name variables" because they are created at run time (when your app is executing)' makes me wonder if it would be easier to code one Label object at coding time, and then create the additional objects at RunTime?
I would always have at least 1 but could have as many as 10-20 as a txt files is read in the initial Loading operation. Does that make sense?
Yes, and it's the same thing: I was just using "named variables" as an example to show you in code you might be familiar with.
For i = 0 to N
Dim lbl As New Label
lbl.Text = i.ToString()
Me.GB_Table.Controls.Add(lbl)
End For
...
For Each ctrl As Control In Me.GB_Table.Controls
If TypeOf ctrl Is LabelThen
Console.WriteLine(ctrl.Text)
End If
Next
lbl
only exists inside the first loop, but all the Labels are available in the second.