Hi Everyone
I am trying to write a program using random number generator in a GUI environment. When the plus label is clicked it generates and display an additional problem. The random number generator generates numbers between 1 and 100.
A textbox is used to enter the answer.
When the "check" button is clicked it checks to see if the answer is right, if it is a message display "correct", if not a message displays "incorrect".
I have most of the code. I used a function to get the sum of the two random numbers. I am trying to use a sub procedure to compare. When I do, everything comes up "correct". Here's what I have. If anyone one can help me with this I will appreciate it. It seems like my problem lies in the textbox somewhere when I am comparing my answers.![]()
Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim answer As Integer
answer = SumofNumber()
Me.txtAnswer.Focus()
Me.lblNum1.Text = num1
Me.lblNum2.Text = num2
Me.lblPlus.Text = plus
Me.lblMessage.Text = ""
End Sub
Function SumofNumber() As Integer
num1 = rand.Next(1, 101)
num2 = rand.Next(1, 101)
plus = ("+")
equal = ("=")
Return (num1 + num2)
End Function
Private Sub btnCheck_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCheck.Click
Dim answer As Integer
Me.txtAnswer.Text = result
result = Val(Me.txtAnswer.Text)
compareSum(answer)
End Sub
Sub compareSum(ByVal answer As Integer)
If result <> answer Then
lblMessage.Text = "Incorrect"
End If
If answer = result Then
lblMessage.Text = "Correct"
End If
End Sub
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
rand = New Random
End Sub
thanks in advance
computer_mom![]()
End Class




Reply With Quote