I'm trying "upgrading myself" (I'm afraid it won't be easy...) from VB 5.0
to VB 2005 Express Edition.
In VB 5, I was used to creating indexed controls at design time, let's say
lbl(0), lbl(1), and so on...
It was quite easy : creating lbl, setting the Index property (0), then
Ctrl-C on lbl(0), and Ctrl-V as often as necessary.
In VB 2005 Express, I'm unable to find the Index property of a label.
In order to understand, I have designed -- under VB 5 -- a very simple
project with 2 indexed labels and I have loaded it under VB 2005. It runs
but, according to the Property window, these controls are named "_lbl_0" and
"_lbl_1" instead of the expected lbl(0) and lbl(1).
In the source code , I can read "lbl(i)", as I have written under VB5.
Having a look at the code, I'm unable to understand how it works. It appears
to me much more difficult than VB5.
Do I have to build my form ONLY with some code and to create my controls at
run time ?
Is it possible to declare an array of labels ? How ?
Thanks a lot for your help.
Gabriel
--
Terry
First the bad news... There is no such thing as a control array in
VB.NET. Sure, you can create arrays and lists of controls, but you
have to do it your self, the ide won't do it for you.
Now, there may or may not be good news here depending on what you want
to do with the array? Why don't you give an example of what it is you
wish to accomplish, and someone can probably point you to a solution.
--
Tom Shelton
I'll use your example:
2 labels on the form named
- lbl1
- lbl2
to access them you can use
Me.Controls.Item("<Control Name>").text = "text"
So you could do it in a loop
For x = 1 To 2
Me.Controls.Item("lbl" & 1).Text = "Text for Label 1"
Me.Controls.Item("lbl" & 2).Text = "Text for Label 2"
Next
or access it directly
Me.Controls.Item("lbl1").Text = "Text for Label 1"
Me.Controls.Item("lbl2").Text = "Text for Label 2"
or you could set up an array to hold the label names
dim arrArray() as string
arrArray(1) = "lbl1"
arrArray(2) = "lbl2"
Me.Controls.Item(arrArray(1)).Text = "Text for Label 1"
There are other methods out there that check all the controls and then you have to make sure the control is the right type, etc. I found this way allowed me to access just the controls I wanted.
>> On Tuesday, October 23, 2007 5:47 PM Terry wrote:
>> Control arrays no longer are supported. Look up ' Control array' in the msdn
>> documentaion for workarounds. Documentation is available here:
>> http://msdn2.microsoft.com/en-us/default.aspx
>>
>>
>> --
>> Terry
>>
>>
>> "degas" wrote:
I suspect the OP may have found an answer already in the intervening three
years.
--
Andrew