1. Engineering
  2. Computer Science
  3. with this code add to the exit button that allows...

Question: with this code add to the exit button that allows...

Question details

WITH THIS CODE, ADD TO THE EXIT BUTTON THAT ALLOWS THE USER TO SEE UPON EXITING, HOW MANY QUESTIONS THEY GOT RIGHT AND WRONG.

Public Class Form1
Dim r As Random = New Random
Dim no1, no2 As Integer
Private Sub rdbAdd_CheckedChanged(sender As Object, e As EventArgs) Handles rdbAdd.CheckedChanged
txtAnswer.Clear()
txtAnswer.BackColor = Color.White
no1 = randomInt()
no2 = randomInt()
lblOperation.Text = "+"
txtNumber1.Text = no1.ToString()
txtNumber2.Text = no2.ToString()
End Sub
Public Function randomInt() As Integer
Return r.Next(20, 120)
End Function

Private Sub rdbSub_CheckedChanged(sender As Object, e As EventArgs) Handles rdbSub.CheckedChanged
txtAnswer.Clear()
txtAnswer.BackColor = Color.White
no1 = randomInt()
no2 = randomInt()
lblOperation.Text = "-"
txtNumber1.Text = no1.ToString()
txtNumber2.Text = no2.ToString()
End Sub

Private Sub rdbMul_CheckedChanged(sender As Object, e As EventArgs) Handles rdbMul.CheckedChanged
txtAnswer.Clear()
txtAnswer.BackColor = Color.White
no1 = randomInt()
no2 = randomInt()
lblOperation.Text = "*"
txtNumber1.Text = no1.ToString()
txtNumber2.Text = no2.ToString()
End Sub

Private Sub rdbDiv_CheckedChanged(sender As Object, e As EventArgs) Handles rdbDiv.CheckedChanged
txtAnswer.Clear()
txtAnswer.BackColor = Color.White
no1 = randomInt()
lblOperation.Text = "/"
txtNumber1.Text = no1.ToString()
Do
no2 = randomInt()
If no1 Mod no2 = 0 Then
Exit Do
End If
Loop
txtNumber2.Text = no2.ToString()

End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
'Close the form'
Me.Close()

End Sub

Private Sub btnCheckAns_Click(sender As Object, e As EventArgs) Handles btnCheckAns.Click
Dim userAnswer = txtAnswer.Text

Try
Integer.TryParse(txtAnswer.Text, userAnswer)
If rdbAdd.Checked = True Then
If Val(txtAnswer.Text) = no1 + no2 Then
txtAnswer.BackColor = Color.Green
Else
txtAnswer.BackColor = Color.Red
End If
End If
If rdbSub.Checked = True Then
If Val(txtAnswer.Text) = no1 - no2 Then
txtAnswer.BackColor = Color.Green
Else
txtAnswer.BackColor = Color.Red
End If
End If
If rdbMul.Checked = True Then
If Val(txtAnswer.Text) = no1 * no2 Then
txtAnswer.BackColor = Color.Green
Else
txtAnswer.BackColor = Color.Red
End If
End If
If rdbDiv.Checked = True Then

End If
If Val(txtAnswer.Text) = no1 / no2 Then
txtAnswer.BackColor = Color.Green
Else
txtAnswer.BackColor = Color.Red


End If
Catch ex As Exception
MsgBox("Please enter Intger")
End Try
End Sub
End Class

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution