469,282 Members | 2,034 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

label control arrays

I know this is probably talk about millions of time here, but I cant seem
to find a close one, I am so used to the vb6 control array, now that I have
to use vb.net for my project, I like to do the following in vb.net with this
vb6 way:

In vb6, I would create five labels array on a form:
lblDisplay(1)...lblDisplay(5), and in each label I would have tag property:
Display1...Display5.

Then, in code (omitted some connection string below):

rst = new ADODB.Recordset
for i = 1 to lblDisplay.Count
rst.open("select Value from Tags where Name='" & lblDisplay(i).Tag &
"'")
lblDisplay(i).Caption = rst!Value
next i
How would I do this in VB.NET? I read some books, they mentioned about
using the Tag property to identify the control, but I want to get your
opinion on this.
Thanks!!!
Nov 21 '05 #1
7 15022
This should get you started:

In the Load event of a form:

Dim LBL(5) As Label
Dim i As Int32
For i = 0 To 5
LBL(i) = New Label()
LBL(i).Top = i * 22
LBL(i).Text = "LBL" & i.ToString
Me.Controls.Add(LBL(i))
Next

You can use a Datatable instead of a Recordset as your data store.

The .Net Label has a Tag property.

www.charlesfarriersoftware.com

"anthony" wrote:
I know this is probably talk about millions of time here, but I cant seem
to find a close one, I am so used to the vb6 control array, now that I have
to use vb.net for my project, I like to do the following in vb.net with this
vb6 way:

In vb6, I would create five labels array on a form:
lblDisplay(1)...lblDisplay(5), and in each label I would have tag property:
Display1...Display5.

Then, in code (omitted some connection string below):

rst = new ADODB.Recordset
for i = 1 to lblDisplay.Count
rst.open("select Value from Tags where Name='" & lblDisplay(i).Tag &
"'")
lblDisplay(i).Caption = rst!Value
next i
How would I do this in VB.NET? I read some books, they mentioned about
using the Tag property to identify the control, but I want to get your
opinion on this.
Thanks!!!

Nov 21 '05 #2
This should get you started:

In the Load event of a form:

Dim LBL(5) As Label
Dim i As Int32
For i = 0 To 5
LBL(i) = New Label()
LBL(i).Top = i * 22
LBL(i).Text = "LBL" & i.ToString
Me.Controls.Add(LBL(i))
Next

You can use a Datatable instead of a Recordset as your data store.

The .Net Label has a Tag property.

www.charlesfarriersoftware.com

"anthony" wrote:
I know this is probably talk about millions of time here, but I cant seem
to find a close one, I am so used to the vb6 control array, now that I have
to use vb.net for my project, I like to do the following in vb.net with this
vb6 way:

In vb6, I would create five labels array on a form:
lblDisplay(1)...lblDisplay(5), and in each label I would have tag property:
Display1...Display5.

Then, in code (omitted some connection string below):

rst = new ADODB.Recordset
for i = 1 to lblDisplay.Count
rst.open("select Value from Tags where Name='" & lblDisplay(i).Tag &
"'")
lblDisplay(i).Caption = rst!Value
next i
How would I do this in VB.NET? I read some books, they mentioned about
using the Tag property to identify the control, but I want to get your
opinion on this.
Thanks!!!

Nov 21 '05 #3
Anthony,

Yes I have answered this often, however it is simple, create yourself that
array of labels and than you can use the code as you do. Using VBNet you can
put any control in an array and mixed exactly as you want.

dim myLblArr() as label = new label() {label1,label2,label3,label5,etc)

As question, is there any reason why you use ADODB, with that you have
forever to deploy as well the DLL, why not ADONET?

I hope this helps?

Cor

"anthony"
I know this is probably talk about millions of time here, but I cant seem
to find a close one, I am so used to the vb6 control array, now that I
have
to use vb.net for my project, I like to do the following in vb.net with
this
vb6 way:

In vb6, I would create five labels array on a form:
lblDisplay(1)...lblDisplay(5), and in each label I would have tag
property:
Display1...Display5.

Then, in code (omitted some connection string below):

rst = new ADODB.Recordset
for i = 1 to lblDisplay.Count
rst.open("select Value from Tags where Name='" & lblDisplay(i).Tag &
"'")
lblDisplay(i).Caption = rst!Value
next i
How would I do this in VB.NET? I read some books, they mentioned about
using the Tag property to identify the control, but I want to get your
opinion on this.
Thanks!!!

Nov 21 '05 #4
Anthony,

Yes I have answered this often, however it is simple, create yourself that
array of labels and than you can use the code as you do. Using VBNet you can
put any control in an array and mixed exactly as you want.

dim myLblArr() as label = new label() {label1,label2,label3,label5,etc)

As question, is there any reason why you use ADODB, with that you have
forever to deploy as well the DLL, why not ADONET?

I hope this helps?

Cor

"anthony"
I know this is probably talk about millions of time here, but I cant seem
to find a close one, I am so used to the vb6 control array, now that I
have
to use vb.net for my project, I like to do the following in vb.net with
this
vb6 way:

In vb6, I would create five labels array on a form:
lblDisplay(1)...lblDisplay(5), and in each label I would have tag
property:
Display1...Display5.

Then, in code (omitted some connection string below):

rst = new ADODB.Recordset
for i = 1 to lblDisplay.Count
rst.open("select Value from Tags where Name='" & lblDisplay(i).Tag &
"'")
lblDisplay(i).Caption = rst!Value
next i
How would I do this in VB.NET? I read some books, they mentioned about
using the Tag property to identify the control, but I want to get your
opinion on this.
Thanks!!!

Nov 21 '05 #5
Thanks for your reply,

It looks like I have to create the label controls in run time.
"Charlie" <Ch*****@discussions.microsoft.com> wrote in message
news:D3**********************************@microsof t.com...
This should get you started:

In the Load event of a form:

Dim LBL(5) As Label
Dim i As Int32
For i = 0 To 5
LBL(i) = New Label()
LBL(i).Top = i * 22
LBL(i).Text = "LBL" & i.ToString
Me.Controls.Add(LBL(i))
Next

You can use a Datatable instead of a Recordset as your data store.

The .Net Label has a Tag property.

www.charlesfarriersoftware.com

"anthony" wrote:
I know this is probably talk about millions of time here, but I cant seem to find a close one, I am so used to the vb6 control array, now that I have to use vb.net for my project, I like to do the following in vb.net with this vb6 way:

In vb6, I would create five labels array on a form:
lblDisplay(1)...lblDisplay(5), and in each label I would have tag property: Display1...Display5.

Then, in code (omitted some connection string below):

rst = new ADODB.Recordset
for i = 1 to lblDisplay.Count
rst.open("select Value from Tags where Name='" & lblDisplay(i).Tag &
"'")
lblDisplay(i).Caption = rst!Value
next i
How would I do this in VB.NET? I read some books, they mentioned about
using the Tag property to identify the control, but I want to get your
opinion on this.
Thanks!!!

Nov 21 '05 #6
Thanks,

Looks like I have to create the labels in run time, can it be done in design
time?

I used ADODB because I don't know much about ADONET, the project now didn't
allow me much time to research, but certainly now I will look at this in
depth.
"Cor Ligthert" <no************@planet.nl> wrote in message
news:en**************@TK2MSFTNGP10.phx.gbl...
Anthony,

Yes I have answered this often, however it is simple, create yourself that
array of labels and than you can use the code as you do. Using VBNet you can put any control in an array and mixed exactly as you want.

dim myLblArr() as label = new label() {label1,label2,label3,label5,etc)

As question, is there any reason why you use ADODB, with that you have
forever to deploy as well the DLL, why not ADONET?

I hope this helps?

Cor

"anthony"
I know this is probably talk about millions of time here, but I cant seem to find a close one, I am so used to the vb6 control array, now that I
have
to use vb.net for my project, I like to do the following in vb.net with
this
vb6 way:

In vb6, I would create five labels array on a form:
lblDisplay(1)...lblDisplay(5), and in each label I would have tag
property:
Display1...Display5.

Then, in code (omitted some connection string below):

rst = new ADODB.Recordset
for i = 1 to lblDisplay.Count
rst.open("select Value from Tags where Name='" & lblDisplay(i).Tag &
"'")
lblDisplay(i).Caption = rst!Value
next i
How would I do this in VB.NET? I read some books, they mentioned about
using the Tag property to identify the control, but I want to get your
opinion on this.
Thanks!!!


Nov 21 '05 #7
Anthony,

You don't have to create the labels in runtime.
Only that array I showed you, in another format.

dim myLblArr() as label = {label1,label2,label3,label5,etc}

Cor

Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Joe | last post: by
31 posts views Thread by jcrouse | last post: by
reply views Thread by anthony | last post: by
8 posts views Thread by Arpan | last post: by
2 posts views Thread by rn5a | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.