Scanning Option Group (VB 6 Option Button Control Array)

  • Thread starter Thread starter Michael D. Ober
  • Start date Start date
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.
 
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
 
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.
 
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"
 
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"
 
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
 
Back
Top