By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,552 Members | 927 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,552 IT Pros & Developers. It's quick & easy.

Loop Control array

P: n/a
Hello,
Could you explain me,In VB6 using control array,and how
about VB.net.

Thanks
Nov 20 '05 #1
Share this Question
Share on Google+
20 Replies


P: n/a
Hi Samean,

A lot of methods, so tell what you want to archieve because a general one
does probably not help you.

Cor
Nov 20 '05 #2

P: n/a
Hi,

http://www.windowsforms.com/default....mID=16&mid=142

http://msdn.microsoft.com/library/de...et05132003.asp

Ken
---------------------------
"samean" <an*******@discussions.microsoft.com> wrote in message
news:70****************************@phx.gbl...
Hello,
Could you explain me,In VB6 using control array,and how
about VB.net.

Thanks
Nov 20 '05 #3

P: n/a

"samean" <an*******@discussions.microsoft.com> wrote in message
news:70****************************@phx.gbl...
Could you explain me,In VB6 using control array,and how
about VB.net.


For VB6, ask in microsoft.public.vb.general.discussion, and for .NET, they
no longer exist.
Nov 20 '05 #4

P: n/a
>and for .NET, they no longer exist.

Are you sure of that, I though exactly the oposite.

Cor
Nov 20 '05 #5

P: n/a

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:Os*************@TK2MSFTNGP12.phx.gbl...
and for .NET, they no longer exist.


Are you sure of that, I though exactly the oposite.


Control arrays no longer exist in .NET, I know that for sure. However, I may
have slightly misinterpreted the poster's question. I read "How do you loop
through a control array in VB6 and .NET?" The question may actually have
been, "How do I loop through controls? Please show me using a control array
in VB6 and however it's done in .NET."
Nov 20 '05 #6

P: n/a
Hi Jeff,

All controls exist as arrays now (or reference in a control.collections
however that is for me the same, it is uses Ilist).

That means that there are as I wrote more possibilities, I give here 3
however it is of course endless.

One which looks I thought the most as the one that was in VB6.
\\\needs two buttons and a label on a form
Dim btnArea As Button() = New Button() {Button1, Button2}
For Each btn As Button In btnArea
AddHandler btn.MouseLeave, AddressOf Button_MouseLeave
Next
Private Sub Button_MouseEnter(ByVal sender As Object, _
ByVal e As System.EventArgs)
Me.Label1.Text = DirectCast(sender, Button).Name
End Sub
///
The most standard one
\\\
For each btn as button in me.controls
if typeof btn Is Button then
bla bla bla
end if
next
///
And the one I like the most.
\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doset(Me)
End Sub
Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
AddHandler ctr.LostFocus, AddressOf meLostFocus
AddHandler ctr.GotFocus, AddressOf meGotFocus
doSet(ctr)
Next
End Sub
Private Sub meLostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
last = DirectCast(sender, Control).Name
End Sub
Private Sub meGotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Control).Text = last
End Sub
///

I hope this gives some idea of going throug a control array?

Cor
Nov 20 '05 #7

P: n/a

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
All controls exist as arrays now (or reference in a control.collections
however that is for me the same, it is uses Ilist).


Well, it is NOT the same as what VB6 called a "control array," and I think
it's confusing to people who have used both to state that there are "control
arrays" in .NET. Most VB6'ers would assume that means that you can have
controls on a form named, for example:

txtData(0)
txtData(1)
txtData(2)
etc.
Nov 20 '05 #8

P: n/a
Jeff,

Did I say it is the same, you said there exist no array of controls in
VBNet.

However that was not the question of the OP. (As you stated already)

I know that it is not what was called in VB6 a control array, luckily not.

However there is the control.collection in every control which implements
from the same class as array does.

:-)

Cor
Well, it is NOT the same as what VB6 called a "control array," and I think
it's confusing to people who have used both to state that there are "control arrays" in .NET. Most VB6'ers would assume that means that you can have
controls on a form named, for example:

txtData(0)
txtData(1)
txtData(2)
etc.

Nov 20 '05 #9

P: n/a

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Did I say it is the same, you said there exist no array of controls in
VBNet.
No, I didn't say "array of controls"; in fact I didn't use the term at all,
at first. The original poster said "control array" and I said they don't
exist in .NET:

-------------------------------------------- Could you explain me,In VB6 using control array,and how
about VB.net.


For VB6, ask in microsoft.public.vb.general.discussion, and for .NET, they
no longer exist.
--------------------------------------------
Nov 20 '05 #10

P: n/a
>
Did I say it is the same, you said there exist no array of controls in
VBNet.
No, I didn't say "array of controls"; in fact I didn't use the term at

all, at first. The original poster said "control array" and I said they don't
exist in .NET:


Yes and it that you are wrong.

Cor
Nov 20 '05 #11

P: n/a

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eI**************@TK2MSFTNGP11.phx.gbl...
Did I say it is the same, you said there exist no array of controls in
VBNet.


No, I didn't say "array of controls"; in fact I didn't use the term at
all, at first. The original poster said "control array" and I said they don't exist in .NET:


Yes and it that you are wrong.


From MSDN (specifically
http://msdn.microsoft.com/library/de...basicnet.asp):

--------------
In Visual Basic 6.0, control arrays could be used to specify a group of
controls that shared a set of events. The controls had to be of the same
type, and they had to have the same name.

In Visual Basic .NET, control arrays are no longer supported. Changes to the
event model make control arrays unnecessary. Just as control arrays in
Visual Basic 6.0 could share events, the event model in Visual Basic .NET
allows any event handler to handle events from multiple controls. In effect,
this allows you to create groups of controls of disparate types that share
the same events.
--------------

Plain and simple, I don't care if you like to use the terms "array of
controls" and "control arrays" interchangably; the fact is that as far as
Microsoft is concerned they mean different things. We're all professionals
here (for the most part; there are some beginners) and we should be using
correct terminology, especially those of us answering questions, which you
do a lot of (and that's a good thing!). We owe it to the people asking
questions to avoid giving (potentially) confusing advice.
Nov 20 '05 #12

P: n/a

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eI**************@TK2MSFTNGP11.phx.gbl...
Did I say it is the same, you said there exist no array of controls in
VBNet.


No, I didn't say "array of controls"; in fact I didn't use the term at
all, at first. The original poster said "control array" and I said they don't exist in .NET:


Yes and it that you are wrong.


From MSDN (specifically
http://msdn.microsoft.com/library/de...basicnet.asp):

--------------
In Visual Basic 6.0, control arrays could be used to specify a group of
controls that shared a set of events. The controls had to be of the same
type, and they had to have the same name.

In Visual Basic .NET, control arrays are no longer supported. Changes to the
event model make control arrays unnecessary. Just as control arrays in
Visual Basic 6.0 could share events, the event model in Visual Basic .NET
allows any event handler to handle events from multiple controls. In effect,
this allows you to create groups of controls of disparate types that share
the same events.
--------------

Plain and simple, I don't care if you like to use the terms "array of
controls" and "control arrays" interchangably; the fact is that as far as
Microsoft is concerned they mean different things. We're all professionals
here (for the most part; there are some beginners) and we should be using
correct terminology, especially those of us answering questions, which you
do a lot of (and that's a good thing!). We owe it to the people asking
questions to avoid giving (potentially) confusing advice.
Nov 20 '05 #13

P: n/a
Interesting discussion between you and Mr. Cor. Your last note is interesting in that one can allow the same event handler to handle events from multiple controls. Do you have a code snippet that does this? I don't understand how it's done.
--
Dennis in Houston
"Jeff Johnson [MVP: VB]" wrote:

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eI**************@TK2MSFTNGP11.phx.gbl...
> Did I say it is the same, you said there exist no array of controls in
> VBNet.

No, I didn't say "array of controls"; in fact I didn't use the term at
all, at first. The original poster said "control array" and I said they don't exist in .NET:


Yes and it that you are wrong.


From MSDN (specifically
http://msdn.microsoft.com/library/de...basicnet.asp):

--------------
In Visual Basic 6.0, control arrays could be used to specify a group of
controls that shared a set of events. The controls had to be of the same
type, and they had to have the same name.

In Visual Basic .NET, control arrays are no longer supported. Changes to the
event model make control arrays unnecessary. Just as control arrays in
Visual Basic 6.0 could share events, the event model in Visual Basic .NET
allows any event handler to handle events from multiple controls. In effect,
this allows you to create groups of controls of disparate types that share
the same events.
--------------

Plain and simple, I don't care if you like to use the terms "array of
controls" and "control arrays" interchangably; the fact is that as far as
Microsoft is concerned they mean different things. We're all professionals
here (for the most part; there are some beginners) and we should be using
correct terminology, especially those of us answering questions, which you
do a lot of (and that's a good thing!). We owe it to the people asking
questions to avoid giving (potentially) confusing advice.

Nov 20 '05 #14

P: n/a
Interesting discussion between you and Mr. Cor. Your last note is interesting in that one can allow the same event handler to handle events from multiple controls. Do you have a code snippet that does this? I don't understand how it's done.
--
Dennis in Houston
"Jeff Johnson [MVP: VB]" wrote:

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eI**************@TK2MSFTNGP11.phx.gbl...
> Did I say it is the same, you said there exist no array of controls in
> VBNet.

No, I didn't say "array of controls"; in fact I didn't use the term at
all, at first. The original poster said "control array" and I said they don't exist in .NET:


Yes and it that you are wrong.


From MSDN (specifically
http://msdn.microsoft.com/library/de...basicnet.asp):

--------------
In Visual Basic 6.0, control arrays could be used to specify a group of
controls that shared a set of events. The controls had to be of the same
type, and they had to have the same name.

In Visual Basic .NET, control arrays are no longer supported. Changes to the
event model make control arrays unnecessary. Just as control arrays in
Visual Basic 6.0 could share events, the event model in Visual Basic .NET
allows any event handler to handle events from multiple controls. In effect,
this allows you to create groups of controls of disparate types that share
the same events.
--------------

Plain and simple, I don't care if you like to use the terms "array of
controls" and "control arrays" interchangably; the fact is that as far as
Microsoft is concerned they mean different things. We're all professionals
here (for the most part; there are some beginners) and we should be using
correct terminology, especially those of us answering questions, which you
do a lot of (and that's a good thing!). We owe it to the people asking
questions to avoid giving (potentially) confusing advice.

Nov 20 '05 #15

P: n/a

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:81**********************************@microsof t.com...
Interesting discussion between you and Mr. Cor. Your last note is interesting in that one can allow the same event handler to handle events from multiple controls. Do you have a code snippet that does this? I don't understand how it's done.


Sure, but I'm going to be lazy about it: look back in this group for a
thread titled "Handler question" from 2004-07-29 5:41PM (EDT) and read the
responses.
Nov 20 '05 #16

P: n/a

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:81**********************************@microsof t.com...
Interesting discussion between you and Mr. Cor. Your last note is interesting in that one can allow the same event handler to handle events from multiple controls. Do you have a code snippet that does this? I don't understand how it's done.


Sure, but I'm going to be lazy about it: look back in this group for a
thread titled "Handler question" from 2004-07-29 5:41PM (EDT) and read the
responses.
Nov 20 '05 #17

P: n/a
Dennis,

In this thread are two samples from it, use the last one it is recursive and
very handy.

Cor
Nov 20 '05 #18

P: n/a
Jeff,

This is not the first time in this newsgroup that you try to convert VB6 to
VBNet.

The VB6 type control array does luckily not exist in VBNet.

However that does not mean that VBNet has no arrays of controls. You see I
write arrays, because every control (from which the Form is one) has a
control.collection.

http://msdn.microsoft.com/library/de...trolstopic.asp

The reason I take so much time in this thread is that I do not want that
people get the wrong advice and think that because you said "there is no
Control Array in VBNet" the cannot do the things they want to do.

You see seldom the regulars in this newsgroup tell people here in this group
that things cannot be done. And mostly they wait than a long time before
answering. A lot of those things are than even done by our appreciated
cleansweaper Peter Huang who sometimes than even finds a solution or take it
back to his backoffice.

Cor

Cor
Nov 20 '05 #19

P: n/a
Dennis,

In this thread are two samples from it, use the last one it is recursive and
very handy.

Cor
Nov 20 '05 #20

P: n/a
Jeff,

This is not the first time in this newsgroup that you try to convert VB6 to
VBNet.

The VB6 type control array does luckily not exist in VBNet.

However that does not mean that VBNet has no arrays of controls. You see I
write arrays, because every control (from which the Form is one) has a
control.collection.

http://msdn.microsoft.com/library/de...trolstopic.asp

The reason I take so much time in this thread is that I do not want that
people get the wrong advice and think that because you said "there is no
Control Array in VBNet" the cannot do the things they want to do.

You see seldom the regulars in this newsgroup tell people here in this group
that things cannot be done. And mostly they wait than a long time before
answering. A lot of those things are than even done by our appreciated
cleansweaper Peter Huang who sometimes than even finds a solution or take it
back to his backoffice.

Cor

Cor
Nov 20 '05 #21

This discussion thread is closed

Replies have been disabled for this discussion.