0

宿題の一部です。構造化データが必要で、質問を .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
4

0 に答える 0