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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

17 Experts available now in Live!

Get 1:1 Help Now