Scanning Option Group (VB 6 Option Button Control Array)

M

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.
 
C

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
 
M

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.
 
C

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"
 
M

Michael D. Ober

This is what I was looking for.

Thanks, Cor.

Cor Ligthert said:
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"
 
C

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top