R
Rango Sheriff
Guest
Hello, I have been given a final year mini project to build a quiz that can ask 20 random questions. and at the end of the quiz it then displays the result.<br> I have tried to research so far and I found help at Multiwingspan.co.uk, this helped so much but I am now stuck in how to evaluate the answers at the end of the score, I am using a text file called "Question.txt".
<strong>please help </strong>. Here is the code
<i>
<hr/>
Imports System <br>
Imports System.IO <br>
Public Class Form2 <br>
Private Structure myQuestion
Public strQuestionText As String
Public strSuggestion() As String
Public strAnswer As String
End Structure
Dim strTheQuestions(20) As myQuestion
Dim intCurrentQuestion As Integer
Dim intCorrect As Integer
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
intCurrentQuestion = 0
intCorrect = 0
' open up a stream to the file we need
Using sr As StreamReader = File.OpenText("Question.txt")
'counter variables for loops to read in question data
Dim intQuestionCounter As Integer, intAnswerCounter As Integer
'Loops through each question
For intQuestionCounter = 0 To 20
'reads the question text of thenext item
strTheQuestions(intQuestionCounter).strQuestionText = sr.ReadLine()
'initialises the array of answers
ReDim strTheQuestions(intQuestionCounter).strSuggestion(3)
'reads in the set of suggestions for this question
For intAnswerCounter = 0 To 3
strTheQuestions(intQuestionCounter).strSuggestion(intAnswerCounter) = sr.ReadLine()
Next
'reads the answer for the question
strTheQuestions(intQuestionCounter).strAnswer = sr.ReadLine()
Next
End Using
lblQuestionText.Text = (intCurrentQuestion + 1) & ". " & strTheQuestions(intCurrentQuestion).strQuestionText
Dim intcounter As Integer
lstAnswers.Items.Clear()
For intcounter = 0 To 3
lstAnswers.Items.Add(strTheQuestions(intCurrentQuestion).strSuggestion(intcounter))
Next
showQuestion()
End Sub
Private Sub showQuestion()
lblQuestionText.Text = (intCurrentQuestion + 1) & ". " & strTheQuestions(intCurrentQuestion).strQuestionText
Dim intcounter As Integer
lstAnswers.Items.Clear()
For intcounter = 0 To 3
lstAnswers.Items.Add(strTheQuestions(intCurrentQuestion).strSuggestion(intcounter))
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If lstAnswers.SelectedIndex = -1 Then Exit Sub
Dim strUserAnswer As String
strUserAnswer = lstAnswers.SelectedItem
If strUserAnswer = strTheQuestions(intCurrentQuestion).strAnswer Then
intCorrect = intCorrect + 1
End If
intCurrentQuestion = intCurrentQuestion + 1
If intCurrentQuestion = 20 Then
MsgBox("The quiz is over, you scored " & intCorrect & " out of 20.")
Else
showQuestion()
End If
End Sub
End Class
</i>
Continue reading...
<strong>please help </strong>. Here is the code
<i>
<hr/>
Imports System <br>
Imports System.IO <br>
Public Class Form2 <br>
Private Structure myQuestion
Public strQuestionText As String
Public strSuggestion() As String
Public strAnswer As String
End Structure
Dim strTheQuestions(20) As myQuestion
Dim intCurrentQuestion As Integer
Dim intCorrect As Integer
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
intCurrentQuestion = 0
intCorrect = 0
' open up a stream to the file we need
Using sr As StreamReader = File.OpenText("Question.txt")
'counter variables for loops to read in question data
Dim intQuestionCounter As Integer, intAnswerCounter As Integer
'Loops through each question
For intQuestionCounter = 0 To 20
'reads the question text of thenext item
strTheQuestions(intQuestionCounter).strQuestionText = sr.ReadLine()
'initialises the array of answers
ReDim strTheQuestions(intQuestionCounter).strSuggestion(3)
'reads in the set of suggestions for this question
For intAnswerCounter = 0 To 3
strTheQuestions(intQuestionCounter).strSuggestion(intAnswerCounter) = sr.ReadLine()
Next
'reads the answer for the question
strTheQuestions(intQuestionCounter).strAnswer = sr.ReadLine()
Next
End Using
lblQuestionText.Text = (intCurrentQuestion + 1) & ". " & strTheQuestions(intCurrentQuestion).strQuestionText
Dim intcounter As Integer
lstAnswers.Items.Clear()
For intcounter = 0 To 3
lstAnswers.Items.Add(strTheQuestions(intCurrentQuestion).strSuggestion(intcounter))
Next
showQuestion()
End Sub
Private Sub showQuestion()
lblQuestionText.Text = (intCurrentQuestion + 1) & ". " & strTheQuestions(intCurrentQuestion).strQuestionText
Dim intcounter As Integer
lstAnswers.Items.Clear()
For intcounter = 0 To 3
lstAnswers.Items.Add(strTheQuestions(intCurrentQuestion).strSuggestion(intcounter))
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If lstAnswers.SelectedIndex = -1 Then Exit Sub
Dim strUserAnswer As String
strUserAnswer = lstAnswers.SelectedItem
If strUserAnswer = strTheQuestions(intCurrentQuestion).strAnswer Then
intCorrect = intCorrect + 1
End If
intCurrentQuestion = intCurrentQuestion + 1
If intCurrentQuestion = 20 Then
MsgBox("The quiz is over, you scored " & intCorrect & " out of 20.")
Else
showQuestion()
End If
End Sub
End Class
</i>
Continue reading...