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
195 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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 …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 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