多项选择测验

时间:2014-09-22 19:04:09

标签: xml vb.net

我必须进行20个问题的测验。 测验在问题和答案中都有图像。 即计算双积分(双积分的图像) 答案将是图像再次或只是一个数字。即结果是2或图像。

到目前为止我所做的是以下内容:

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

我的问题是如何在答案中的问题和文字中提供图像

0 个答案:

没有答案