如何在VB中进行多项选择测试?

时间:2013-04-07 18:54:47

标签: vb.net structured-data

这是家庭作业的一部分。我必须有结构化数据,并阅读.dat文件中的问题。到目前为止,这就是我所拥有的。我在Private Sub cmdNext_Click函数中遇到的麻烦最多。有4个单选按钮可以显示答案,标签必须显示每个问题,当我单击下一个按钮时,它会显示下一个问题并记录提交的答案。最后,我必须显示一个消息框,其中包含答案和评分。

在一个模块中,我必须把我老师给我们的代码放在一起:

Module MyModule

Structure testQuestion
    <VBFixedString(100)> Public question As String
    <VBFixedString(30)> Public choiceA As String
    <VBFixedString(30)> Public choiceB As String
    <VBFixedString(30)> Public choiceC As String
    <VBFixedString(30)> Public choiceD As String
    <VBFixedString(1)> Public correctAnswer As String

End Structure
Public Const noOfQuestions = 10
Public test(noOfQuestions - 1) As testQuestion
Public Const correctAnswer = 100 / noOfQuestions
Public Const wrongAnswer = correctAnswer / 2

然后在表格中我到目前为止已经有了这段代码:

Option Explicit On

Public Class Example

Private Sub Example_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Main.Show()
    Me.Hide()
End Sub

Private Sub ShowQuestion()
    FileOpen(1, "Test1.dat", OpenMode.Random, , , Len(test(0)))

End Sub

Private Sub MarkTest()

    Dim grade As Integer = 0


    cmdNext.Text = "Test finished!"
    opt1.Enabled = False
    opt2.Enabled = False
    opt3.Enabled = False
    opt4.Enabled = False


End Sub





Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click

    If opt1.Checked = True Then
        test(noOfQuestions - 1) = opt1.Text
    ElseIf opt2.Checked = True Then
        test(noOfQuestions - 1) = opt2.Text
    ElseIf opt3.Checked = True Then
        test(noOfQuestions - 1) = opt3.Text
    ElseIf opt4.Checked = True Then
        test(noOfQuestions - 1) = opt4.Text
    End If

    opt1.Focus()
    If noOfQuestions < 10 Then
        lblNumber.Text = lblNumber.Text + 1

        lblQuestion.Text = test(testQuestion)
        opt1.Text = choiceA(noOfQuestions - 1, 1)
        opt2.Text = testQuestion(noOfQuestions - 1, 2)
        opt3.Text = testQuestion(noOfQuestions - 1, 3)
        opt4.Text = testQuestion(noOfQuestions - 1, 4)

        If lblNumber.Text = 10 Then
            cmdNext.Text = "Submit"
        End If

    Else
        MarkTest()
    End If

End Sub

End Class

0 个答案:

没有答案