Help on VB.NET

Santoss

New member
Joined
Mar 28, 2007
Messages
4
Programming Experience
Beginner
Hello everyone!
I am new here, I just registered. I don't know if I should be posting this here but I have an question to make about VB.NET.

I want to create a label array in way I can refer to each label like this:

For x=0 to 10
label(x).text = "Hello"
next

I searched on internet and on books but "they" are never specific..:(

I hope you can help me.

Thanks

Best regards,

Santoss
 
VB.NET:
Dim MyLabels(10) As Labels

For Counter As Integer = 0 to 10
  MyLabels(Counter) = New Label
  With MyLabels(Counter)
    .Left = 100
    .Top = MyLabels(Counter - 1).Top + 2 + MyLabels(Counter - 1).Height
    .Text = "Hello Label #" & Counter.ToString
  End With

  Me.Controls.Add(MyLabels(Counter))
Next Counter

all you need to do with this example is make sure the first label is placed somewhere on the form
 
Thanks for your answer!
I typed that code just like you posted here, but at 1st line apears a blue underline on the last word 'Labels' and a note says "Type 'Labels' is not declared". How can I solve this?
 
this line:
Dim MyLabels(10) As Labels

should be:
Dim MyLabels(10) As Label


also this was just an example, you will need to modify it to do what you need done
 
Back
Top