Original Post
Designing a quiz game for a semester project, and near finished. I have the quiz questions, answer options, correct answer and a check to see if it has been played in a 2d array.
I use the rnd function to get a random question and check, but sometimes after play I am getting a bad baaad error, and I have no clue why I am getting it.
Here is the code in the class that I am running, at least the error that it is showing to go to.
The error it gives is "An unhandled exception of type ''System.StackOverflowException'' occurred in microsoft.visualbasic.dll" and highlights the line intRandomQuestion = CInt(Int(6 * Rnd()))
I''m clueless myself.
Public Class QuizPlayer
#Region "Declarations and Constructor"
''Structure for name and score of each player
Private Structure PlayerData
Dim strPlayerName As String ''Player''s Name Storage
Dim intPlayerScore As Integer ''Player''s Score
Dim chrPlayerAnswer As Char
End Structure
''Structure for output of question to form
Private Structure CurrentQuestion
Dim strQuestion As String
Dim strAnswer1 As String
Dim strAnswer2 As String
Dim strAnswer3 As String
Dim strAnswer4 As String
Dim strCorrectAnswer As String
Dim strQuestionUsed As String
End Structure
''All three players data structures defined
Dim plyPlayer1 As PlayerData
Dim plyPlayer2 As PlayerData
Dim plyPlayer3 As PlayerData
''One structure of CurrentQuestion
Dim crqActiveQuestion As CurrentQuestion
''Integer for question selection
Dim intRandomQuestion As Integer
#Region "Question and Answer Array"
''Array for Quiz Questions and Answers, uses 2d set up table.
Dim strQandA(,) As String = { _
{"Test Question! What is 2 + 2?", "3?", "2?", "4?", "8?", "C", "0"}, _
{"Test Question! What is 2 + 2?", "3?", "2?", "4?", "8?", "C", "0"}, _
{"Test Question! What is 2 + 2?", "3?", "2?", "4?", "8?", "C", "0"}, _
{"Test Question! What is 2 + 2?", "3?", "2?", "4?", "8?", "C", "0"}, _
{"Test Question! What is 2 + 2?", "3?", "2?", "4?", "8?", "C", "0"}, _
{"Test Question! What is 2 + 2?", "3?", "2?", "4?", "8?", "C", "0"}, _
{"Test Question! What is 2 + 2?", "3?", "2?", "4?", "8?", "C", "0"}, _
{"Test Question! What is 2 + 2?", "3?", "2?", "4?", "8?", "C", "0"} _
}
#End Region
''Constructor
Sub New()
End Sub
Sub New(ByVal newPlayer1Name As String, ByVal newPlayer2Name As String, ByVal newPlayer3Name As String)
Me.Player1Name = newPlayer1Name
Me.Player2Name = newPlayer2Name
Me.Player3Name = newPlayer3Name
End Sub
#End Region
#Region "Properties"
Property Player1Name() As String
Get
Player1Name = plyPlayer1.strPlayerName
End Get
Set(ByVal Value As String)
plyPlayer1.strPlayerName = Value
End Set
End Property
Property Player2Name() As String
Get
Player2Name = plyPlayer2.strPlayerName
End Get
Set(ByVal Value As String)
plyPlayer2.strPlayerName = Value
End Set
End Property
Property Player3Name() As String
Get
Player3Name = plyPlayer3.strPlayerName
End Get
Set(ByVal Value As String)
plyPlayer3.strPlayerName = Value
End Set
End Property
ReadOnly Property Player1Score() As Integer
Get
Player1Score = plyPlayer1.intPlayerScore
End Get
End Property
ReadOnly Property Player2Score() As Integer
Get
Player2Score = plyPlayer2.intPlayerScore
End Get
End Property
ReadOnly Property Player3Score() As Integer
Get
Player3Score = plyPlayer3.intPlayerScore
End Get
End Property
Property Player1Answer() As Char
Get
Player1Answer = plyPlayer1.chrPlayerAnswer
End Get
Set(ByVal Value As Char)
plyPlayer1.chrPlayerAnswer = Value
End Set
End Property
Property Player2Answer() As Char
Get
Player2Answer = plyPlayer2.chrPlayerAnswer
End Get
Set(ByVal Value As Char)
plyPlayer2.chrPlayerAnswer = Value
End Set
End Property
Property Player3Answer() As Char
Get
Player3Answer = plyPlayer3.chrPlayerAnswer
End Get
Set(ByVal Value As Char)
plyPlayer3.chrPlayerAnswer = Value
End Set
End Property
ReadOnly Property Question() As String
Get
Question = crqActiveQuestion.strQuestion
End Get
End Property
ReadOnly Property Answer1() As String
Get
Answer1 = crqActiveQuestion.strAnswer1
End Get
End Property
ReadOnly Property Answer2() As String
Get
Answer2 = crqActiveQuestion.strAnswer2
End Get
End Property
ReadOnly Property Answer3() As String
Get
Answer3 = crqActiveQuestion.strAnswer3
End Get
End Property
ReadOnly Property Answer4() As String
Get
Answer4 = crqActiveQuestion.strAnswer4
End Get
End Property
ReadOnly Property CorrectAnswer() As String
Get
CorrectAnswer = crqActiveQuestion.strCorrectAnswer
End Get
End Property
ReadOnly Property QuestionUsed() As String
Get
QuestionUsed = crqActiveQuestion.strQuestionUsed
End Get
End Property
#End Region
#Region "Methods"
Sub Player1Correct()
plyPlayer1.intPlayerScore += 100
End Sub
Sub Player2Correct()
plyPlayer2.intPlayerScore += 100
End Sub
Sub Player3Correct()
plyPlayer3.intPlayerScore += 100
End Sub
Sub NextQuestion()
intRandomQuestion = CInt(Int(6 * Rnd()))
''Checks if question has been asked, if not sets data to properties
If strQandA(intRandomQuestion, 6) = "0" Then
crqActiveQuestion.strQuestion = strQandA(intRandomQuestion, 0)
crqActiveQuestion.strAnswer1 = strQandA(intRandomQuestion, 1)
crqActiveQuestion.strAnswer2 = strQandA(intRandomQuestion, 2)
crqActiveQuestion.strAnswer3 = strQandA(intRandomQuestion, 3)
crqActiveQuestion.strAnswer4 = strQandA(intRandomQuestion, 4)
crqActiveQuestion.strCorrectAnswer = strQandA(intRandomQuestion, 5)
strQandA(intRandomQuestion, 6) = 1
Else
NextQuestion()
End If
End Sub
Function GetPlayer1Name() As String
End Function
Function GetPlayer2Name() As String
End Function
Function GetPlayer3Name() As String
End Function
Sub CheckAnswers()
If plyPlayer1.chrPlayerAnswer = strQandA(intRandomQuestion, 5) Then
Player1Correct()
End If
If plyPlayer2.chrPlayerAnswer = strQandA(intRandomQuestion, 5) Then
Player2Correct()
End If
If plyPlayer3.chrPlayerAnswer = strQandA(intRandomQuestion, 5) Then
Player3Correct()
End If
End Sub
#End Region
End Class
Here is the ENTIRE class, but the main problem seems to be pointing to the rand feature in the "NextQuestion" sub routine.
Thanks to anyone who spots it.