Form1.Designer.VB
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.InstructionLabel = New System.Windows.Forms.Label
Me.QuestionLabel = New System.Windows.Forms.Label
Me.AnswerTextBox = New System.Windows.Forms.TextBox
Me.SubmitButton = New System.Windows.Forms.Button
Me.ScoreLabel = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'InstructionLabel
'
Me.InstructionLabel.AutoSize = True
Me.InstructionLabel.Location = New System.Drawing.Point(13, 13)
Me.InstructionLabel.Name = "InstructionLabel"
Me.InstructionLabel.Size = New System.Drawing.Size(224, 13)
Me.InstructionLabel.TabIndex = 0
Me.InstructionLabel.Text = "Translate the following sentences into French:"
'
'QuestionLabel
'
Me.QuestionLabel.AutoSize = True
Me.QuestionLabel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.QuestionLabel.Location = New System.Drawing.Point(16, 43)
Me.QuestionLabel.Name = "QuestionLabel"
Me.QuestionLabel.Size = New System.Drawing.Size(2, 15)
Me.QuestionLabel.TabIndex = 1
'
'AnswerTextBox
'
Me.AnswerTextBox.Location = New System.Drawing.Point(16, 72)
Me.AnswerTextBox.Name = "AnswerTextBox"
Me.AnswerTextBox.Size = New System.Drawing.Size(468, 20)
Me.AnswerTextBox.TabIndex = 2
'
'SubmitButton
'
Me.SubmitButton.Location = New System.Drawing.Point(409, 98)
Me.SubmitButton.Name = "SubmitButton"
Me.SubmitButton.Size = New System.Drawing.Size(75, 23)
Me.SubmitButton.TabIndex = 3
Me.SubmitButton.Text = "Submit"
Me.SubmitButton.UseVisualStyleBackColor = True
'
'ScoreLabel
'
Me.ScoreLabel.AutoSize = True
Me.ScoreLabel.Location = New System.Drawing.Point(13, 103)
Me.ScoreLabel.Name = "ScoreLabel"
Me.ScoreLabel.Size = New System.Drawing.Size(169, 13)
Me.ScoreLabel.TabIndex = 4
Me.ScoreLabel.Text = "0 Answered, 0 Correct, 0 Incorrect"
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(496, 139)
Me.Controls.Add(Me.ScoreLabel)
Me.Controls.Add(Me.SubmitButton)
Me.Controls.Add(Me.AnswerTextBox)
Me.Controls.Add(Me.QuestionLabel)
Me.Controls.Add(Me.InstructionLabel)
Me.Name = "Form1"
Me.Text = "Q&A"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents InstructionLabel As System.Windows.Forms.Label
Friend WithEvents QuestionLabel As System.Windows.Forms.Label
Friend WithEvents AnswerTextBox As System.Windows.Forms.TextBox
Friend WithEvents SubmitButton As System.Windows.Forms.Button
Friend WithEvents ScoreLabel As System.Windows.Forms.Label
End Class
Form1.VB
Public Class Form1
Private xmlrdr As New Xml.XmlTextReader("qa.xml")
Private totalquestions As Integer = 0
Private correctanswers As Integer = 0
Private wronganswers As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
xmlrdr.ReadToFollowing("qa")
Me.totalquestions += 1
Me.QuestionLabel.Text = xmlrdr.GetAttribute("question")
End Sub
Private Sub GetNextQuestion()
If Not Me.xmlrdr.ReadToNextSibling("qa") Then
MessageBox.Show(String.Format("You got a {0}%.", (Math.Round(Me.correctanswers / Me.totalquestions, 2)) * 100), "You have answered all the questions!", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Me.totalquestions += 1
Me.QuestionLabel.Text = xmlrdr.GetAttribute("question")
End If
End Sub
Private Sub SubmitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SubmitButton.Click
If Me.AnswerTextBox.Text = xmlrdr.GetAttribute("answer") Then
MessageBox.Show("Correct!", "Question Answered", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.correctanswers += 1
Else
MessageBox.Show(String.Format("Sorry, the correct answer is:{0}{1}", ControlChars.NewLine, xmlrdr.GetAttribute("answer")), "Question Answered", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.wronganswers += 1
End If
Me.AnswerTextBox.Text = String.Empty
Me.ScoreLabel.Text = String.Format("{0} Answered, {1} Correct, {2} Incorrect", Me.totalquestions, Me.correctanswers, Me.wronganswers)
Me.GetNextQuestion()
End Sub
End Class
QA.XML
<?xml version="1.0" encoding="utf-8" ?>
<questions>
<qa question="Do you live in England?" answer="Tu es all en Angleterre?" />
<qa question="Do you speak French?" answer="Parlez-vous fran?ais?" />
<qa question="The cat ran up the tree." answer="Le chat a fonctionn vers le haut de l'arbre." />
<qa question="There are four wheels on the yellow bus." answer="Il y a quatre roues sur l'autobus jaune." />
<qa question="Many people like red hats." answer="Beaucoup de gens aiment les chapeaux rouges." />
<qa question="I like to run in the sun." answer="J'aime courir au soleil." />
<qa question="How high can you jump?" answer="Combien haut pouvez-vous sauter?" />
<qa question="What is your favorite color?" answer="Quelle est votre couleur prfre?" />
<qa question="There are seven people in my class." answer="Il y a sept personnes dans ma classe." />
<qa question="Tomorrow is my father’s birthday." answer="Le demain est l'anniversaire de mon père." />
<qa question="Vanillia is my favorite flavor of icecream." answer="Vanillia est ma saveur prfre de glace." />
</questions>