(Solved) – I’m having more trouble than I thought with a random equation generator in Visual basic

(solved)-–-i’m-having-more-trouble-than-i-thought-with-a-random-equation-generator-in-visual-basic

I’m trying to do an assignment in my VB book, Programming challenge 7. Integer Math Tutor. I’m mostly trying to figure out how to use a loop with the code.

Buttons
-Check Answer
-Next Problem

Radio Buttons
-Add
-Subtract
-Multiply
-Divide

Input
-Textbox(Answer)

Output
-Question/ Equation
-Response(good job, wrong answer)

Here’s whats inside my form class. I can’t figure out if the check answer button is actually working correctly and that If Not Integer statement is there because when I used inputNumb = txtInputNumb.Text I would get an error.

Public Class Form1

Dim rand As Random
Dim ranNumb1, ranNumb2, inputNumb, sumNumb As Integer

Private Sub rabtnAdd_CheckedChanged(sender As Object, e As EventArgs) Handles rabtnAdd.CheckedChanged

    Do
        ' Output Random Number
        rand = New Random
        ranNumb1 = rand.Next(20, 121)
        ranNumb2 = rand.Next(20, 121)
        lblQuestion.Text = ranNumb1 & ("   ") & ranNumb2 & (" = ")

        sumNumb = ranNumb1 = ranNumb2

        If Not Integer.TryParse(txtInputNumb.Text, inputNumb) Then
            lblTalkBack.Text = ("Error in box B, Interger Only.")
            Exit Sub
        End If

        lblTalkBack.Text = sumNumb

    Loop


End Sub

Private Sub btnCheck_Click(sender As Object, e As EventArgs) Handles btnCheck.Click

    If inputNumb = sumNumb Then
        lblTest.Text = ("good")
    Else
        lblTest.Text = ("bad")
    End If

End Sub

Private Sub rabtnSubt_CheckedChanged(sender As Object, e As EventArgs) Handles rabtnSubt.CheckedChanged

    rand = New Random
    ranNumb1 = rand.Next(20, 121)
    ranNumb2 = rand.Next(20, 121)
    lblQuestion.Text = ranNumb1 & (" - ") & ranNumb2 & (" = ")

    lblTest.Text = ("test2")
End Sub

Private Sub rabtnMulti_CheckedChanged(sender As Object, e As EventArgs) Handles rabtnMulti.CheckedChanged

    rand = New Random
    ranNumb1 = rand.Next(20, 121)
    ranNumb2 = rand.Next(20, 121)
    lblQuestion.Text = ranNumb1 & (" * ") & ranNumb2 & (" = ")

    lblTest.Text = ("test3")
End Sub

Private Sub rabtnDivi_CheckedChanged(sender As Object, e As EventArgs) Handles rabtnDivi.CheckedChanged

    rand = New Random
    ranNumb1 = rand.Next(20, 121)
    ranNumb2 = rand.Next(20, 121)
    lblQuestion.Text = ranNumb1 & (" / ") & ranNumb2 & (" = ")

    lblTest.Text = ("test4")
End Sub

End Class

Leave a Reply

Your email address will not be published. Required fields are marked *