Где происходит исключение System.StackOverflowException в моей викторине VB.NET? - PullRequest
0 голосов
/ 19 февраля 2019

введите описание изображения здесь

Ошибка, кажется, происходит в Dim totalAdd, totalSub, totalDiv и totalMult, но это странно, так как она работала как раз раньше, и не может увидеть, где она моглаошиблись.

Public Class QuizForm
    Public Property Sign As String
    Dim Rnd1 As New Random
    Dim Rnd2 As New Random
    Dim Num1 = Rnd1.Next(1, 10)
    Dim Num2 = Rnd2.Next(1, 10)
    Dim totalAdd = Num1 + Num2
    Dim totalSub = Num1 - Num2
    Dim totalDiv = Num1 / Num2
    Dim totalMult = Num1 * Num2
    Dim Score As Integer
    Dim Questions As Integer
    Dim prompt As String
    Private Sub QuizForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        TextBox1.Text = Num1
        TextBox2.Text = Num2
        signLabel.Text = Sign

        If Sign = "+" Then
            answerLabel.Text = totalAdd
        ElseIf Sign = "-" Then
            answerLabel.Text = totalSub
        ElseIf Sign = "÷" Then
            answerLabel.Text = totalDiv
        Else
            answerLabel.Text = totalMult
        End If
    End Sub

    Private Sub Checker_Click(sender As Object, e As EventArgs) Handles Checker.Click
        If Sign = "+" Then
            If answerBox.Text = answerLabel.Text Then
                prompt = "Correct"
                Score += 1
                answerBox.Text = ""
            Else
                prompt = "Incorrect"
                answerBox.Text = ""
            End If


            Dim confirm As Integer = MessageBox.Show(prompt, "Answer", MessageBoxButtons.OK)
            If confirm = DialogResult.OK Then
                Num1 = Rnd1.Next(1, 10)
                Num2 = Rnd2.Next(1, 15)

                totalAdd = Num1 + Num2
                TextBox1.Text = Num1
                TextBox2.Text = Num2
                answerLabel.Text = totalAdd
                scoreLabel.Text = "Score: " & Score
            End If

            Questions += 1
            questionNum.Text = ("Question Number " & Questions & "/10")


        ElseIf Sign = "-" Then
            If answerBox.Text = answerLabel.Text Then
                prompt = "Correct"
                Score += 1
                answerBox.Text = ""
            Else
                prompt = "Incorrect"
                answerBox.Text = ""
            End If


            Dim confirm As Integer = MessageBox.Show(prompt, "Answer", MessageBoxButtons.OK)
            If confirm = DialogResult.OK Then
                Num1 = Rnd1.Next(1, 15)
                Num2 = Rnd2.Next(1, 10)

                totalSub = Num1 - Num2
                TextBox1.Text = Num1
                TextBox2.Text = Num2
                answerLabel.Text = totalSub
                scoreLabel.Text = "Score: " & Score
            End If

            Questions += 1
            questionNum.Text = ("Question Number " & Questions & "/10")

        ElseIf Sign = "÷" Then
            If answerBox.Text = answerLabel.Text Then
                prompt = "Correct"
                Score += 1
                answerBox.Text = ""
            Else
                prompt = "Incorrect"
                answerBox.Text = ""
            End If


            Dim confirm As Integer = MessageBox.Show(prompt, "Answer", MessageBoxButtons.OK)
            If confirm = DialogResult.OK Then
                Num1 = Rnd1.Next(1, 10)
                Num2 = 2

                totalDiv = Num1 / Num2
                TextBox1.Text = Num1
                TextBox2.Text = Num2
                answerLabel.Text = totalDiv
                scoreLabel.Text = "Score: " & Score
            End If

            Questions += 1
            questionNum.Text = ("Question Number " & Questions & "/10")

        Else
            If answerBox.Text = answerLabel.Text Then
                prompt = "Correct"
                Score += 1
                answerBox.Text = ""
            Else
                prompt = "Incorrect"
                answerBox.Text = ""
            End If


            Dim confirm As Integer = MessageBox.Show(prompt, "Answer", MessageBoxButtons.OK)
            If confirm = DialogResult.OK Then
                Num1 = Rnd1.Next(1, 10)
                Num2 = Rnd1.Next(1, 10)

                totalMult = Num1 * Num2
                TextBox1.Text = Num1
                TextBox2.Text = Num2
                answerLabel.Text = totalMult
                scoreLabel.Text = "Score: " & Score
            End If

            Questions += 1
            questionNum.Text = ("Question Number " & Questions & "/10")
        End If
    End Sub

    Private Sub menuButton_Click(sender As Object, e As EventArgs) Handles menuButton.Click
        Dim quiz_menu As New MenuForm
        quiz_menu.Show()
        Me.Hide()
    End Sub
End Class
...