Multible Choice Quiz



i have to make a quiz with 20 questions. the quiz has images in the questions and in the answers also. i.e. calculate the double integral (image of the double integral) the answer will be image again or just a number . i.e the result is 2 or an image.


what i did so far is the following:



Imports System.Xml.Serialization
Imports System.IO
Imports System.Xml

Public Class Form1
Private questions As New List(Of Question)
Private quizPath As String
Private imagesPath As String
Private selecteQuestion As Question
Private score As Integer
Private xRndNo As New List(Of Integer)
Private time As Integer = 10

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim path As String = Application.StartupPath.ToLower.Replace("\bin\debug", "").Replace("\bin\release", "")
quizPath = path.Replace("\bin\Debug\", "")
imagesPath = quizPath + "\images"
quizPath = quizPath + "\quiz.xml"

Try
Dim m_xmld As XmlDocument
Dim m_nodelist As XmlNodeList
Dim m_node As XmlNode

m_xmld = New XmlDocument()
m_xmld.Load(quizPath)
m_nodelist = m_xmld.SelectNodes("/questions/question")
For Each m_node In m_nodelist
Dim question As New Question()
question.Name = m_node.SelectSingleNode("name").InnerText
question.Answer1 = m_node.SelectSingleNode("answer1").InnerText
question.Answer2 = m_node.SelectSingleNode("answer2").InnerText
question.Answer3 = m_node.SelectSingleNode("answer3").InnerText
question.Answer4 = m_node.SelectSingleNode("answer4").InnerText
question.Correct = Convert.ToInt32(m_node.SelectSingleNode("correct").InnerText)
questions.Add(question)
Next
Catch errorVariable As Exception
MessageBox.Show(errorVariable.ToString())
End Try
countdown.Text = time
scorelabel.Text = score
End Sub

Private Sub loadNextQuestion()
If xRndNo.Count = questions.Count Then
endOfQuiz()
End If
Dim xGenerator As System.Random = New System.Random()
Dim randomNumb As Integer = 0

While True
randomNumb = xGenerator.Next(0, questions.Count)
If xRndNo.Contains(randomNumb) Then
Continue While
Else
xRndNo.Add(randomNumb)
Exit While
End If
End While

selecteQuestion = questions.Item(randomNumb)
Label1.Text = selecteQuestion.Name
PictureBox1.Image = Image.FromFile(imagesPath + "\" + selecteQuestion.Answer1)
PictureBox2.Image = Image.FromFile(imagesPath + "\" + selecteQuestion.Answer2)
PictureBox3.Image = Image.FromFile(imagesPath + "\" + selecteQuestion.Answer3)
PictureBox4.Image = Image.FromFile(imagesPath + "\" + selecteQuestion.Answer4)
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
End Sub

Private Sub endOfQuiz()
Timer1.Enabled = False
MessageBox.Show("End of quiz. Your score is: " + score.ToString)
Me.Close()
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If RadioButton1.Checked = True Or RadioButton2.Checked = True Or RadioButton3.Checked = True Or RadioButton4.Checked = True Then
If selecteQuestion.Correct = 1 And RadioButton1.Checked = True Then
score = score + 1
scorelabel.Text = score.ToString
ElseIf selecteQuestion.Correct = 2 And RadioButton2.Checked = True Then
score = score + 1
scorelabel.Text = score.ToString
ElseIf selecteQuestion.Correct = 3 And RadioButton3.Checked = True Then
score = score + 1
scorelabel.Text = score.ToString
ElseIf selecteQuestion.Correct = 4 And RadioButton3.Checked = True Then
score = score + 1
scorelabel.Text = score.ToString
Else
scorelabel.Text = score.ToString
End If
loadNextQuestion()
Else
MessageBox.Show("Select the awnser")
End If
End Sub


Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
time = time - 1
countdown.Text = time
If Convert.ToInt32(countdown.Text) <= 0 Then
Timer1.Enabled = False
endOfQuiz()
End If
End Sub

Private Sub Start_Click(sender As Object, e As EventArgs) Handles Start.Click
loadNextQuestion()
Timer1.Enabled = True
Start.Enabled = False
End Sub

End Class
Public Class Question
Public Name As String
Public Answer1 As String
Public Answer2 As String
Public Answer3 As String
Public Answer4 As String
Public Correct As Integer
End Class


My question is how to also have image in my question and text in the answers


No comments:

Post a Comment