Solved

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

Posted on 2006-11-28
3
176 Views
Last Modified: 2010-04-23
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,
0
Comment
Question by:GabicusC
  • 2
3 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18030416
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
0
 
LVL 29

Accepted Solution

by:
Nightman earned 500 total points
ID: 18030426
You can't use select case - this checks against a single value. You would have to do if..then..else..etc

e.g.

    If RadioButton1.Checked Then
      MessageBox.Show("1 is checked") 'replace with your code
    ElseIf RadioButton2.Checked Then
      MessageBox.Show("2 is checked")'replace with your code
    Else
      MessageBox.Show("3 is checked")'replace with your code
    End If
0
 
LVL 29

Expert Comment

by:Nightman
ID: 18030481
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
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now