Control loop

operator

New member
Joined
Sep 28, 2005
Messages
4
Programming Experience
Beginner
Hi all,

I am trying to design a test page that has multiple qustions. Each question has 4 possible answers. These answers have been assigned to radio buttons so that the user can choose only one answer at a time.
The question: How can I set a control that checks if an answer is choosen? and at the same time if the user didn't make a selecetion at all, how can I warn the user to make a selection? Actualy I have managed to do all these however I was not able warn the user to make a selection and unless a selecetion is being made the user will get the same messege. Here is my code:
Dim status AsBoolean
status = False
WhileNot status
MsgBox ("Please answer questio 1!")
If RadioButton1.Checked = TrueOr RadioButton2.Checked = TrueOr RadioButton3.Checked = TrueOr RadioButton4.Checked = TrueThen
durum = True
MsgBox("You can proceed with question 2")

EndIf
EndWhile
 
Why not this?
VB.NET:
[COLOR=#0000ff]If[/COLOR][SIZE=2] RadioButton1.Checked = [/SIZE][SIZE=2][COLOR=#0000ff]True [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Or[/COLOR][/SIZE][SIZE=2] RadioButton2.Checked = [/SIZE][SIZE=2][COLOR=#0000ff]True [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Or[/COLOR][/SIZE][SIZE=2] RadioButton3.Checked = [/SIZE][SIZE=2][COLOR=#0000ff]True [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Or[/COLOR][/SIZE][SIZE=2] RadioButton4.Checked = [/SIZE][SIZE=2][COLOR=#0000ff]True [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]durum = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]MsgBox([/SIZE][SIZE=2][COLOR=#800000]"You can proceed with question 2"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=blue]Else[/COLOR][/SIZE]
MsgBox([SIZE=2][COLOR=#800000]"Please answer one of the Qs before proceed"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=blue]Exit Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=blue]End if[/COLOR][/SIZE]


notice that i would simplify this iterating through the RB's collection but anyway the code above will work just fine ;)
 
Thanks a lot for the promt response kulrom. However the problem with that is I have 10 questions on the same page. They all have 4 possible answers to choose from. I guess some how I need to make the other questions read only until the question in line is answered. Because right now what happens is that the user is able answer question 2 and the messege to aswer question 1 appears, right after that you can proceed to question 3 appears on the screen. This way the code is gonna get really messy I guess. Any recommendations??
 
Hello there,
I have brought a simple solution for the problem. I am not so sure if it is a appropriate one but it works.
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
While CheckBox1.Checked = False And CheckBox2.Checked = False And CheckBox3.Checked = False And CheckBox4.Checked = False
MsgBox("Please make a selection for question 1")
Exit Sub
End While
While CheckBox5.Checked = False And CheckBox6.Checked = False And CheckBox7.Checked = False And CheckBox8.Checked = False
MsgBox("Please make a selection for question 2")
Exit Sub
End While
While CheckBox9.Checked = False And CheckBox10.Checked = False And CheckBox11.Checked = False And CheckBox12.Checked = False
MsgBox("Please make a selection for question 3")
Exit Sub
End While




End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End
Class
' This way, if the user doesn't make a selection for question number 1, he won't be able to advance to question number2.
' I am planning to do the same kind of thing for if the customer checks more than one box for one question. Is there a better way of doing this?
best Regards
 
you could just put each question in its own groupbox, have them disabled (except Q1) by default and when the user clicks one of the values in the groupbox it will enable the next groupbox..

See attached :)

oh this was made in VS2003
 

Attachments

  • WindowsApplication1.zip
    30.6 KB · Views: 27
Back
Top