这是家庭作业的一部分。我必须有结构化数据,并阅读 .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