Link to home
Start Free TrialLog in
Avatar of Richard Comito
Richard ComitoFlag for United States of America

asked on

Is it possible to write a Select Case Statment to check if a Radio Button is checked in side a group box?

I have  form with a group box with 3 radio buttons inside the box.  I would like to check and see which radio button is checked so I can enable different controls on the form.  if it is possible then how would I go about starting to write the code for this?

Thanks,
Avatar of sirbounty
sirbounty
Flag of United States of America image

something like...

for each ctl as control in controls
  if typeof ctl is radiobutton then
    select case ctl.name
          case "Radio1"
          case "Radio2"
          case "Radio3"
    end select
  end if
next
ASKER CERTIFIED SOLUTION
Avatar of Nightman
Nightman
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well, of course sirbounty's 'case' statement will work ;)

But then you have to iterate through all controls in the form, which is probably not necessary. You could make it more efficient just by iteration through the groupbox vontrols collection (if you wanted to use that approach):

for each ctl as control in MyGroupBox.controls
  if typeof ctl is radiobutton then
    select case ctl.name
          case "Radio1"
           If radio1.checked then
             MessageBox.Show("1 is checked") 'replace with your code
           endif
          case "Radio2"
           If radio2.checked then
             MessageBox.Show("2 is checked") 'replace with your code
           endif
          case "Radio3"
           If radio3.checked then
             MessageBox.Show("3 is checked") 'replace with your code
           endif
    end select
  end if
next