我的任务是创建一个允许用户在同一个数组中输入问题和答案(真或假)的程序,如果您要阅读该文件,则该程序如下所示:
auto
然后需要提出问题并随机选择五个以显示输出。我的问题是,每当我尝试调试时,它都无法读取文件而是返回错误。
"Question 1", "T"
我的问题出现在 LoadData()子行中的这一行:
Private Sub Quiz(sender As System.Object, e As System.EventArgs) Handles btnQuiz.Click
If Viewed = True Then
LoadData()
RandomizeStrings()
Duplicates()
frmQuiz.Show()
correct = 0
answers = 0
count = 0
Else : MsgBox("You must view the slide show before you take the quiz!", MsgBoxStyle.Information, "View Slide Show")
End If
End Sub
Private Sub AddQuestion(sender As System.Object, e As System.EventArgs) Handles btnQuestions.Click
pass = "sample01"
response = InputBox("Please enter the administrator password.", "Password")
If response = pass Then
Do
FileOpen(1, "W:\Visual Studio 2010\Projects\Culminating\assets\questions.txt", OpenMode.Append)
question = InputBox("Enter new question (true or false format).", "New Question")
If question = String.Empty Then
Exit Do
FileClose(1)
End If
answer = InputBox("Enter new answer (either 'T' or 'F').", "New Answer")
answer = StrConv(answer, vbUpperCase)
If answer = String.Empty Then
question = String.Empty
Exit Do
FileClose(1)
End If
WriteLine(1, question, answer)
Loop
Else : MsgBox("Incorrect password. Please enter again.", MsgBoxStyle.Critical, "Incorrect Password")
End If
End Sub
Public Sub LoadData()
FileOpen(1, "W:\Visual Studio 2010\Projects\Culminating\assets\questions.txt", OpenMode.Input)
Do While Not EOF(1)
count = count + 1
Input(1, question(count))
Input(1, answer(count))
Loop
FileClose(1)
End Sub
Public Sub RandomizeStrings()
Dim x As Object
Randomize()
For x = 1 To 5
num(x) = Int((count - 1 + 1) * Rnd() + 1)
Next x
End Sub
Public Sub Duplicates()
Dim y As Object
Dim x As Object
For x = 1 To 4
For y = (x + 1) To 5
If num(x) = num(y) Then
num(x) = Int((count - 1 + 1) * Rnd() + 1)
x = 1
End If
Next y
Next x
End Sub
此时,它给了我这个错误:
对象引用未设置为对象的实例。
我真的不知道我的方式,因为我正在遵循我们的老师给我们的样本,我不想走出困境并使用不同的方法来完成这项任务(即使我认为这已经过时了。