"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.