By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,414 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,414 IT Pros & Developers. It's quick & easy.

My Quiz Program

P: n/a
DAL
I want to build my kid a program that cycles through questions (using a
label for the question), and lets him choose one of two radio buttons for
the right answer. How do I get every set of questions and answers to cycle
through until the last question? Also, how can I give him the score after
the last question. Thank you in advance. DAL.

P.S. As a beginner, I figured I couldn't pass up the chance to learn
something new, and to practice to little I have learned! Thanks.
Feb 18 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"DAL" <da*************@yahoo.com> wrote in
news:#y*************@TK2MSFTNGP15.phx.gbl:
I want to build my kid a program that cycles through questions (using
a label for the question), and lets him choose one of two radio
buttons for the right answer. How do I get every set of questions and
answers to cycle through until the last question? Also, how can I give
him the score after the last question. Thank you in advance. DAL.

P.S. As a beginner, I figured I couldn't pass up the chance to learn
something new, and to practice to little I have learned! Thanks.


Start with a structure, as follows, declared in your general
declarations, right after the "Inherits" statement:

Structure QuestionTemplate
Dim Question As String
Dim Answer() As String
Dim CorrectAnswer As Integer
End Structure : Dim Question() As QuestionTemplate

A structure is a way of "tying" different variables together. In the
example above, tied to each question are two or more possible answers, as
well as a variable indicating which of the answers is correct.

The parentheses "()" denote arrays, which are collections of two or more
related variables of the same type. A number within the array specifies
which member is being scrutinized.

Answer() is an array because we'll have two or more possible answers, and
the one with an index (number in parentheses) equal to "CorrectAnswer" is
the right answer.

Question is an array because you'll have far more than two questions. In
fact, to make things easier, put in the number of questions you're
planning to have (minus one, since the count will start at 0)

You should also declare
CurrentQuestion and CorrectAnswer as Integers to keep track of the
current question and number of correct answers given.

---

I'd also suggest going with Command Buttons rather than Radio Buttons,
which have generally fallen out of favor in Graphical User Interfaces. If
your son is at all internet savvy or you expect him to be in the future,
labels set to look like hyperlinks might even be your best bet.

---

As for counting any correct answers, you can send all answer controls to
the same routine, which would pan out as follows.

If sender.Text = Question(CurrentQuestion),Answer(CorrectAnswer) Then
CorrectAnswers = CorrectAnswers + 1
End If
If CurrentQuestion < Question.GetUpperBound(0) Then
CurrentQuestion = CurrentQuestion + 1
Else
System.Windows.Forms.MessageBox("Congratulations! You got " &
CorrectAnswers & " answers correct!")
CurrentQuestion = 0
End If
Call NextQuestion()

The procedure for populating controls would look something like this, and
would be called upon Form_Load, and from the Button_Click routine.

Label_Question.Text = Question(CurrentQuestion).Question
Button_Answer1.Text = Question(CurrentQuestion).Answer(0)
Button_Answer2.Text = Question(CurrentQuestion).Answer(1)

---

The problem you're left with is populating the structure array with
correct information...

Eventually, you might want to load/save this to a file for easy
editing/augmentation, but for now, simply put it in before you call
NextQuestion() in Form_Load.

Question(0).Question = "Question you wish to ask"
Question(0).Answer(0) = "First Answer"
Question(0).Answer(1) = "Second Answer"
Question(0).CorrectAnswer = (0 or 1)

And repeat for Questions 1 through your maximum.
Feb 18 '06 #2

P: n/a
DAL
Thank you, Confessor.
I think I better read a bit more of my book, before I attempt this feat. I
appreciate the quick response. I saved your reply for reference material.
I'm sure I'll need it tomorrow. DAL.
"The Confessor" <in*****@reply.to.group> wrote in message
news:Xn*********************************@130.81.64 .196...
"DAL" <da*************@yahoo.com> wrote in
news:#y*************@TK2MSFTNGP15.phx.gbl:
I want to build my kid a program that cycles through questions (using
a label for the question), and lets him choose one of two radio
buttons for the right answer. How do I get every set of questions and
answers to cycle through until the last question? Also, how can I give
him the score after the last question. Thank you in advance. DAL.

P.S. As a beginner, I figured I couldn't pass up the chance to learn
something new, and to practice to little I have learned! Thanks.


Start with a structure, as follows, declared in your general
declarations, right after the "Inherits" statement:

Structure QuestionTemplate
Dim Question As String
Dim Answer() As String
Dim CorrectAnswer As Integer
End Structure : Dim Question() As QuestionTemplate

A structure is a way of "tying" different variables together. In the
example above, tied to each question are two or more possible answers, as
well as a variable indicating which of the answers is correct.

The parentheses "()" denote arrays, which are collections of two or more
related variables of the same type. A number within the array specifies
which member is being scrutinized.

Answer() is an array because we'll have two or more possible answers, and
the one with an index (number in parentheses) equal to "CorrectAnswer" is
the right answer.

Question is an array because you'll have far more than two questions. In
fact, to make things easier, put in the number of questions you're
planning to have (minus one, since the count will start at 0)

You should also declare
CurrentQuestion and CorrectAnswer as Integers to keep track of the
current question and number of correct answers given.

---

I'd also suggest going with Command Buttons rather than Radio Buttons,
which have generally fallen out of favor in Graphical User Interfaces. If
your son is at all internet savvy or you expect him to be in the future,
labels set to look like hyperlinks might even be your best bet.

---

As for counting any correct answers, you can send all answer controls to
the same routine, which would pan out as follows.

If sender.Text = Question(CurrentQuestion),Answer(CorrectAnswer) Then
CorrectAnswers = CorrectAnswers + 1
End If
If CurrentQuestion < Question.GetUpperBound(0) Then
CurrentQuestion = CurrentQuestion + 1
Else
System.Windows.Forms.MessageBox("Congratulations! You got " &
CorrectAnswers & " answers correct!")
CurrentQuestion = 0
End If
Call NextQuestion()

The procedure for populating controls would look something like this, and
would be called upon Form_Load, and from the Button_Click routine.

Label_Question.Text = Question(CurrentQuestion).Question
Button_Answer1.Text = Question(CurrentQuestion).Answer(0)
Button_Answer2.Text = Question(CurrentQuestion).Answer(1)

---

The problem you're left with is populating the structure array with
correct information...

Eventually, you might want to load/save this to a file for easy
editing/augmentation, but for now, simply put it in before you call
NextQuestion() in Form_Load.

Question(0).Question = "Question you wish to ask"
Question(0).Answer(0) = "First Answer"
Question(0).Answer(1) = "Second Answer"
Question(0).CorrectAnswer = (0 or 1)

And repeat for Questions 1 through your maximum.

Feb 19 '06 #3

P: n/a
Hi DAL,

I once implemented a similar program, using C# and XML. *If you're familiar
with XML*, you might consider creating your Quiz database in XML, so that
you can easily add new questions and edit existing ones, when your
application is up and running. This way, you can save many "Quiz" files. My
application also included a Quiz editor, in which the Custom XML files could
be created. The main form was a Quiz Viewer, which could be used to launch a
Quiz.

For instance, my XML format was something like :

<?xml version="1.0" encoding="utf-8" ?>
<Test xmlns="http://tempuri.org/Quiz.xsd">
<Problem>
<Question>Which language is my favourite?</Question>
<ChoiceA>VB 7.0</ChoiceA>
<ChoiceB>J2EE</ChoiceB>
<ChoiceC>Swahili</ChoiceC>
<ChoiceD>C#</ChoiceD>
<Correct>A</Correct>
</Problem>
<Problem>
<Question>What does XML stand for?</Question>
<ChoiceA>eXcessively Macabre Legend</ChoiceA>
<ChoiceB>Xylophone, My Choice</ChoiceB>
<ChoiceC>eXtensible Markup Language</ChoiceC>
<ChoiceD>eXtra Murky Lungs</ChoiceD>
<Correct>C</Correct>
</Problem>
</Test>

I did however present the various options using Radiobuttons. The user could
move from 1 question to the next, using the Previous and Next buttons. At
the end of the Quiz, a report was displayed, with gradings.

Just some ideas to get you moving.

Hope that helps,

Regards,

Cerebrus.
"DAL" <da*************@yahoo.com> wrote in message
news:#y*************@TK2MSFTNGP15.phx.gbl...
I want to build my kid a program that cycles through questions (using a
label for the question), and lets him choose one of two radio buttons for
the right answer. How do I get every set of questions and answers to cycle
through until the last question? Also, how can I give him the score after
the last question. Thank you in advance. DAL.

P.S. As a beginner, I figured I couldn't pass up the chance to learn
something new, and to practice to little I have learned! Thanks.

Feb 19 '06 #4

P: n/a
DAL
Thanks Cerebrus99. I could use all the help I can get. I'm racking my brain
over here. Have a great day. DAL.
"Cerebrus99" <zo*****@sify.com> wrote in message
news:uA**************@TK2MSFTNGP09.phx.gbl...
Hi DAL,

I once implemented a similar program, using C# and XML. *If you're
familiar
with XML*, you might consider creating your Quiz database in XML, so that
you can easily add new questions and edit existing ones, when your
application is up and running. This way, you can save many "Quiz" files.
My
application also included a Quiz editor, in which the Custom XML files
could
be created. The main form was a Quiz Viewer, which could be used to launch
a
Quiz.

For instance, my XML format was something like :

<?xml version="1.0" encoding="utf-8" ?>
<Test xmlns="http://tempuri.org/Quiz.xsd">
<Problem>
<Question>Which language is my favourite?</Question>
<ChoiceA>VB 7.0</ChoiceA>
<ChoiceB>J2EE</ChoiceB>
<ChoiceC>Swahili</ChoiceC>
<ChoiceD>C#</ChoiceD>
<Correct>A</Correct>
</Problem>
<Problem>
<Question>What does XML stand for?</Question>
<ChoiceA>eXcessively Macabre Legend</ChoiceA>
<ChoiceB>Xylophone, My Choice</ChoiceB>
<ChoiceC>eXtensible Markup Language</ChoiceC>
<ChoiceD>eXtra Murky Lungs</ChoiceD>
<Correct>C</Correct>
</Problem>
</Test>

I did however present the various options using Radiobuttons. The user
could
move from 1 question to the next, using the Previous and Next buttons. At
the end of the Quiz, a report was displayed, with gradings.

Just some ideas to get you moving.

Hope that helps,

Regards,

Cerebrus.
"DAL" <da*************@yahoo.com> wrote in message
news:#y*************@TK2MSFTNGP15.phx.gbl...
I want to build my kid a program that cycles through questions (using a
label for the question), and lets him choose one of two radio buttons for
the right answer. How do I get every set of questions and answers to
cycle
through until the last question? Also, how can I give him the score after
the last question. Thank you in advance. DAL.

P.S. As a beginner, I figured I couldn't pass up the chance to learn
something new, and to practice to little I have learned! Thanks.


Feb 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.