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
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…

751 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