Radio Button groups

desperado

Well-known member
Joined
Oct 7, 2006
Messages
68
Programming Experience
Beginner
Hi, was wondering if somebody could offer me any help please. i Have 5 questions, and each question has different amount of radio buttons. What i want the program to be able to do is, Make sure A radio button is selected from each question, and if not then a message box should appear. So far i have the following:

If obmale.Value = False Then MsgBox ("Please Answer Question 1")
Else
If obfemale.Value = False Then MsgBox ("Please Answer Question 1")
End If

This i have entered for the first question but it seems to be a little tricky. Straight after this i want to check the second, third, fourth, and fifth question. If some body could help me id appreciate it very much.
 
There should be no reason to have to individually check each question. You should start with your OK button disabled so that the user can't continue. Then you create one CheckedChanged event handler for each set of RadioButtons, e.g.
VB.NET:
Private question1Answered As Boolean = False
Private question2Answered As Boolean = False

Private Sub Question1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged,
                                                                                                         RadioButton2.CheckedChanged,
                                                                                                         RadioButton1.CheckedChanged
    Me.question1Answered = DirectCast(sender, RadioButton).Checked
    Me.SetButtonState()
End Sub

Private Sub Question2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton6.CheckedChanged,
                                                                                                         RadioButton5.CheckedChanged,
                                                                                                         RadioButton4.CheckedChanged
    Me.question2Answered = DirectCast(sender, RadioButton).Checked
    Me.SetButtonState()
End Sub

Private Sub SetButtonState()
    Me.Button1.Enabled = Me.question1Answered AndAlso _
                         Me.question2Answered
End Sub
 
Back
Top