Home All Groups Group Topic Archive Search About

Scanning Option Group (VB 6 Option Button Control Array)

Author
12 Jun 2006 5:03 PM
Michael D. Ober
In VB 6, you can create control arrays for your option groups and scan with
the following code

dim opt as OptionButton
for each opt in OptionGroup
  ' Do something
next opt

I know VB 2005 doesn't have control arrays, so my question is how do I do
the equivalent in VB 2005?

Thanks,
Mike Ober.

Author
12 Jun 2006 6:14 PM
Cor Ligthert [MVP]
Michael,

The difference is that VB6 has no control arrays in the way as they are in
VBNet.
VB6 has only arrays of controls.

In VBNet has every control a collection (array) of the childcontrols it is
using.

Although you can create in VBNet of course as well arrays of controls very
simple even

Dim myControlArray() as Control = {Button1, Button2, Textbox3}

I hope this helps,

Cor

Cor

Show quoteHide quote
"Michael D. Ober" <ober***@.alum.mit.edu.nospam> schreef in bericht
news:%23X8PmIkjGHA.4748@TK2MSFTNGP04.phx.gbl...
>
> In VB 6, you can create control arrays for your option groups and scan
> with
> the following code
>
> dim opt as OptionButton
> for each opt in OptionGroup
>  ' Do something
> next opt
>
> I know VB 2005 doesn't have control arrays, so my question is how do I do
> the equivalent in VB 2005?
>
> Thanks,
> Mike Ober.
>
>
>
Author
12 Jun 2006 6:18 PM
Michael D. Ober
When I create the radio group at design time, what steps do I need to do to
be able to loop through the group?

Mike.

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:%23za69ukjGHA.1264@TK2MSFTNGP05.phx.gbl...
>
> Michael,
>
> The difference is that VB6 has no control arrays in the way as they are in
> VBNet.
> VB6 has only arrays of controls.
>
> In VBNet has every control a collection (array) of the childcontrols it is
> using.
>
> Although you can create in VBNet of course as well arrays of controls very
> simple even
>
> Dim myControlArray() as Control = {Button1, Button2, Textbox3}
>
> I hope this helps,
>
> Cor
>
> Cor
>
> "Michael D. Ober" <ober***@.alum.mit.edu.nospam> schreef in bericht
> news:%23X8PmIkjGHA.4748@TK2MSFTNGP04.phx.gbl...
> >
> > In VB 6, you can create control arrays for your option groups and scan
> > with
> > the following code
> >
> > dim opt as OptionButton
> > for each opt in OptionGroup
> >  ' Do something
> > next opt
> >
> > I know VB 2005 doesn't have control arrays, so my question is how do I
do
> > the equivalent in VB 2005?
> >
> > Thanks,
> > Mike Ober.
> >
> >
> >
>
>
>
Author
12 Jun 2006 6:30 PM
Cor Ligthert [MVP]
Michael,

Depends if it is a radiogroup in a groupbox than you can just do

for each ctr as control in mygroupbox
        dim rdb as radiobutton = directcast(ctr,radiobutton)
        rdb.blabla
        'assuming that there are only radiobuttons otherwise
       If typeof ctr Is Radiobutton then
            etc.
next

Or code like that.

Cor


"Michael D. Ober"

<ober***@.alum.mit.edu.nospam> schreef in bericht
Show quoteHide quote
news:eOaCiykjGHA.4284@TK2MSFTNGP05.phx.gbl...
>
> When I create the radio group at design time, what steps do I need to do
> to
> be able to loop through the group?
>
> Mike.
>
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
> news:%23za69ukjGHA.1264@TK2MSFTNGP05.phx.gbl...
>>
>> Michael,
>>
>> The difference is that VB6 has no control arrays in the way as they are
>> in
>> VBNet.
>> VB6 has only arrays of controls.
>>
>> In VBNet has every control a collection (array) of the childcontrols it
>> is
>> using.
>>
>> Although you can create in VBNet of course as well arrays of controls
>> very
>> simple even
>>
>> Dim myControlArray() as Control = {Button1, Button2, Textbox3}
>>
>> I hope this helps,
>>
>> Cor
>>
>> Cor
>>
>> "Michael D. Ober" <ober***@.alum.mit.edu.nospam> schreef in bericht
>> news:%23X8PmIkjGHA.4748@TK2MSFTNGP04.phx.gbl...
>> >
>> > In VB 6, you can create control arrays for your option groups and scan
>> > with
>> > the following code
>> >
>> > dim opt as OptionButton
>> > for each opt in OptionGroup
>> >  ' Do something
>> > next opt
>> >
>> > I know VB 2005 doesn't have control arrays, so my question is how do I
> do
>> > the equivalent in VB 2005?
>> >
>> > Thanks,
>> > Mike Ober.
>> >
>> >
>> >
>>
>>
>>
>
>
>
Author
12 Jun 2006 6:57 PM
Michael D. Ober
This is what I was looking for.

Thanks, Cor.

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:eNEAE4kjGHA.4776@TK2MSFTNGP05.phx.gbl...
> Michael,
>
> Depends if it is a radiogroup in a groupbox than you can just do
>
> for each ctr as control in mygroupbox
>         dim rdb as radiobutton = directcast(ctr,radiobutton)
>         rdb.blabla
>         'assuming that there are only radiobuttons otherwise
>        If typeof ctr Is Radiobutton then
>             etc.
> next
>
> Or code like that.
>
> Cor
>
>
> "Michael D. Ober"
>
> <ober***@.alum.mit.edu.nospam> schreef in bericht
> news:eOaCiykjGHA.4284@TK2MSFTNGP05.phx.gbl...
> >
> > When I create the radio group at design time, what steps do I need to do
> > to
> > be able to loop through the group?
> >
> > Mike.
> >
> > "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
> > news:%23za69ukjGHA.1264@TK2MSFTNGP05.phx.gbl...
> >>
> >> Michael,
> >>
> >> The difference is that VB6 has no control arrays in the way as they are
> >> in
> >> VBNet.
> >> VB6 has only arrays of controls.
> >>
> >> In VBNet has every control a collection (array) of the childcontrols it
> >> is
> >> using.
> >>
> >> Although you can create in VBNet of course as well arrays of controls
> >> very
> >> simple even
> >>
> >> Dim myControlArray() as Control = {Button1, Button2, Textbox3}
> >>
> >> I hope this helps,
> >>
> >> Cor
> >>
> >> Cor
> >>
> >> "Michael D. Ober" <ober***@.alum.mit.edu.nospam> schreef in bericht
> >> news:%23X8PmIkjGHA.4748@TK2MSFTNGP04.phx.gbl...
> >> >
> >> > In VB 6, you can create control arrays for your option groups and
scan
> >> > with
> >> > the following code
> >> >
> >> > dim opt as OptionButton
> >> > for each opt in OptionGroup
> >> >  ' Do something
> >> > next opt
> >> >
> >> > I know VB 2005 doesn't have control arrays, so my question is how do
I
> > do
> >> > the equivalent in VB 2005?
> >> >
> >> > Thanks,
> >> > Mike Ober.
> >> >
> >> >
> >> >
> >>
> >>
> >>
> >
> >
> >
>
>
Author
12 Jun 2006 6:37 PM
Cor Ligthert [MVP]
Michael,

Have a look at this page as well. Because that a control can be in a control
do you have to evaluate that inside it, this is easy code to do that.

http://www.vb-tips.com/default.aspx?ID=8ff290d4-5c16-4cef-ba06-56e3599238c1

I hope this helps,

Cor


Show quoteHide quote
"Michael D. Ober" <ober***@.alum.mit.edu.nospam> schreef in bericht
news:eOaCiykjGHA.4284@TK2MSFTNGP05.phx.gbl...
>
> When I create the radio group at design time, what steps do I need to do
> to
> be able to loop through the group?
>
> Mike.
>
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
> news:%23za69ukjGHA.1264@TK2MSFTNGP05.phx.gbl...
>>
>> Michael,
>>
>> The difference is that VB6 has no control arrays in the way as they are
>> in
>> VBNet.
>> VB6 has only arrays of controls.
>>
>> In VBNet has every control a collection (array) of the childcontrols it
>> is
>> using.
>>
>> Although you can create in VBNet of course as well arrays of controls
>> very
>> simple even
>>
>> Dim myControlArray() as Control = {Button1, Button2, Textbox3}
>>
>> I hope this helps,
>>
>> Cor
>>
>> Cor
>>
>> "Michael D. Ober" <ober***@.alum.mit.edu.nospam> schreef in bericht
>> news:%23X8PmIkjGHA.4748@TK2MSFTNGP04.phx.gbl...
>> >
>> > In VB 6, you can create control arrays for your option groups and scan
>> > with
>> > the following code
>> >
>> > dim opt as OptionButton
>> > for each opt in OptionGroup
>> >  ' Do something
>> > next opt
>> >
>> > I know VB 2005 doesn't have control arrays, so my question is how do I
> do
>> > the equivalent in VB 2005?
>> >
>> > Thanks,
>> > Mike Ober.
>> >
>> >
>> >
>>
>>
>>
>
>
>
Author
20 Jun 2006 4:56 PM
Kevin
Any idea what the reasoning was behind that decision?

In VB6 I used to have an array of Buttons and only had to have one
Event Handler with a Select Case statement.  Now I have to have ten
different Even Handlers and duplicate a lot of code.  Doesn't make
much sense to me unless I'm missing some easier way to do things.


On Mon, 12 Jun 2006 20:14:05 +0200, "Cor Ligthert [MVP]"
<notmyfirstn***@planet.nl> wrote:

Show quoteHide quote
>Michael,
>
>The difference is that VB6 has no control arrays in the way as they are in
>VBNet.
>VB6 has only arrays of controls.
>
>In VBNet has every control a collection (array) of the childcontrols it is
>using.
>
>Although you can create in VBNet of course as well arrays of controls very
>simple even
>
>Dim myControlArray() as Control = {Button1, Button2, Textbox3}
>
>I hope this helps,
>
>Cor
>
>Cor
>
>"Michael D. Ober" <ober***@.alum.mit.edu.nospam> schreef in bericht
>news:%23X8PmIkjGHA.4748@TK2MSFTNGP04.phx.gbl...
>>
>> In VB 6, you can create control arrays for your option groups and scan
>> with
>> the following code
>>
>> dim opt as OptionButton
>> for each opt in OptionGroup
>>  ' Do something
>> next opt
>>
>> I know VB 2005 doesn't have control arrays, so my question is how do I do
>> the equivalent in VB 2005?
>>
>> Thanks,
>> Mike Ober.
>>
>>
>>
>
Author
20 Jun 2006 5:35 PM
Michael D. Ober
You can add multiple controls to the handler clause on the event handler.
Then you can use a case statement to determine which control triggered the
event.

Mike Ober.

Show quoteHide quote
"Kevin" <kevin@nospam.com> wrote in message
news:30ag9219soar4eretlr6766fp77osl7hed@4ax.com...
> Any idea what the reasoning was behind that decision?
>
> In VB6 I used to have an array of Buttons and only had to have one
> Event Handler with a Select Case statement.  Now I have to have ten
> different Even Handlers and duplicate a lot of code.  Doesn't make
> much sense to me unless I'm missing some easier way to do things.
>
>
> On Mon, 12 Jun 2006 20:14:05 +0200, "Cor Ligthert [MVP]"
> <notmyfirstn***@planet.nl> wrote:
>
> >Michael,
> >
> >The difference is that VB6 has no control arrays in the way as they are
in
> >VBNet.
> >VB6 has only arrays of controls.
> >
> >In VBNet has every control a collection (array) of the childcontrols it
is
> >using.
> >
> >Although you can create in VBNet of course as well arrays of controls
very
> >simple even
> >
> >Dim myControlArray() as Control = {Button1, Button2, Textbox3}
> >
> >I hope this helps,
> >
> >Cor
> >
> >Cor
> >
> >"Michael D. Ober" <ober***@.alum.mit.edu.nospam> schreef in bericht
> >news:%23X8PmIkjGHA.4748@TK2MSFTNGP04.phx.gbl...
> >>
> >> In VB 6, you can create control arrays for your option groups and scan
> >> with
> >> the following code
> >>
> >> dim opt as OptionButton
> >> for each opt in OptionGroup
> >>  ' Do something
> >> next opt
> >>
> >> I know VB 2005 doesn't have control arrays, so my question is how do I
do
> >> the equivalent in VB 2005?
> >>
> >> Thanks,
> >> Mike Ober.
> >>
> >>
> >>
> >
>
Author
21 Jun 2006 1:32 AM
Kevin
How would I do this in VB2005?

X = RandomNumber

For Y = 0 to X
   Label(Y).BackColor = vbGray
Next Y


Now I have Label1, Label2, Label3, etc.


On Tue, 20 Jun 2006 11:35:46 -0600, "Michael D. Ober"
<ober***@.alum.mit.edu.nospam> wrote:

Show quoteHide quote
>
>You can add multiple controls to the handler clause on the event handler.
>Then you can use a case statement to determine which control triggered the
>event.
>
>Mike Ober.
>
>"Kevin" <kevin@nospam.com> wrote in message
>news:30ag9219soar4eretlr6766fp77osl7hed@4ax.com...
>> Any idea what the reasoning was behind that decision?
>>
>> In VB6 I used to have an array of Buttons and only had to have one
>> Event Handler with a Select Case statement.  Now I have to have ten
>> different Even Handlers and duplicate a lot of code.  Doesn't make
>> much sense to me unless I'm missing some easier way to do things.
>>
>>
>> On Mon, 12 Jun 2006 20:14:05 +0200, "Cor Ligthert [MVP]"
>> <notmyfirstn***@planet.nl> wrote:
>>
>> >Michael,
>> >
>> >The difference is that VB6 has no control arrays in the way as they are
>in
>> >VBNet.
>> >VB6 has only arrays of controls.
>> >
>> >In VBNet has every control a collection (array) of the childcontrols it
>is
>> >using.
>> >
>> >Although you can create in VBNet of course as well arrays of controls
>very
>> >simple even
>> >
>> >Dim myControlArray() as Control = {Button1, Button2, Textbox3}
>> >
>> >I hope this helps,
>> >
>> >Cor
>> >
>> >Cor
>> >
>> >"Michael D. Ober" <ober***@.alum.mit.edu.nospam> schreef in bericht
>> >news:%23X8PmIkjGHA.4748@TK2MSFTNGP04.phx.gbl...
>> >>
>> >> In VB 6, you can create control arrays for your option groups and scan
>> >> with
>> >> the following code
>> >>
>> >> dim opt as OptionButton
>> >> for each opt in OptionGroup
>> >>  ' Do something
>> >> next opt
>> >>
>> >> I know VB 2005 doesn't have control arrays, so my question is how do I
>do
>> >> the equivalent in VB 2005?
>> >>
>> >> Thanks,
>> >> Mike Ober.
>> >>
>> >>
>> >>
>> >
>>
>
>
Author
21 Jun 2006 5:55 AM
Cor Ligthert [MVP]
Kevin,

\\\
Dim ctr() As Control = {TextBox1, Button1, label1}
For Each ctrind As Control In ctr
         ctrind.BackColor = Color.Black
Next
///

You find your old method now probably nicer, by most of us did that change.

There are much more methods to identify them by the way even at design time.

Cor

Show quoteHide quote
"Kevin" <kevin@nospam.com> schreef in bericht
news:e88h921v1qson6p8uuaf6uif9fs1dcul4e@4ax.com...
> How would I do this in VB2005?
>
> X = RandomNumber
>
> For Y = 0 to X
>   Label(Y).BackColor = vbGray
> Next Y
>
>
> Now I have Label1, Label2, Label3, etc.
>
>
> On Tue, 20 Jun 2006 11:35:46 -0600, "Michael D. Ober"
> <ober***@.alum.mit.edu.nospam> wrote:
>
>>
>>You can add multiple controls to the handler clause on the event handler.
>>Then you can use a case statement to determine which control triggered the
>>event.
>>
>>Mike Ober.
>>
>>"Kevin" <kevin@nospam.com> wrote in message
>>news:30ag9219soar4eretlr6766fp77osl7hed@4ax.com...
>>> Any idea what the reasoning was behind that decision?
>>>
>>> In VB6 I used to have an array of Buttons and only had to have one
>>> Event Handler with a Select Case statement.  Now I have to have ten
>>> different Even Handlers and duplicate a lot of code.  Doesn't make
>>> much sense to me unless I'm missing some easier way to do things.
>>>
>>>
>>> On Mon, 12 Jun 2006 20:14:05 +0200, "Cor Ligthert [MVP]"
>>> <notmyfirstn***@planet.nl> wrote:
>>>
>>> >Michael,
>>> >
>>> >The difference is that VB6 has no control arrays in the way as they are
>>in
>>> >VBNet.
>>> >VB6 has only arrays of controls.
>>> >
>>> >In VBNet has every control a collection (array) of the childcontrols it
>>is
>>> >using.
>>> >
>>> >Although you can create in VBNet of course as well arrays of controls
>>very
>>> >simple even
>>> >
>>> >Dim myControlArray() as Control = {Button1, Button2, Textbox3}
>>> >
>>> >I hope this helps,
>>> >
>>> >Cor
>>> >
>>> >Cor
>>> >
>>> >"Michael D. Ober" <ober***@.alum.mit.edu.nospam> schreef in bericht
>>> >news:%23X8PmIkjGHA.4748@TK2MSFTNGP04.phx.gbl...
>>> >>
>>> >> In VB 6, you can create control arrays for your option groups and
>>> >> scan
>>> >> with
>>> >> the following code
>>> >>
>>> >> dim opt as OptionButton
>>> >> for each opt in OptionGroup
>>> >>  ' Do something
>>> >> next opt
>>> >>
>>> >> I know VB 2005 doesn't have control arrays, so my question is how do
>>> >> I
>>do
>>> >> the equivalent in VB 2005?
>>> >>
>>> >> Thanks,
>>> >> Mike Ober.
>>> >>
>>> >>
>>> >>
>>> >
>>>
>>
>>