I have a simple form with three unbound text boxes named firstnum, secondnum, sumnum. I populate the firstnum and secondnum with random numbers according to the following code. The student is then to enter the sum of the numbers in sumnum. The code for the form is as follows:
Private Sub Form_Load()]
Dim x as Integer
Dim y as Integer
x=Int((10-0+1)*Rnd+0)
y=Int((10-0+1)*Rnd+0)
firstnum.value=x
secondnum.value=y
End Sub
Private Sub sumnum_LostFocus()
If sumnum.value=x+y Then
MsgBox ("Good job"
Else
MsgBox ("Bad job"
End If
End Sub
I am able to populate the firstnum and secondnum text boxes without any problem. My problem is that I can't get the if, then statement to evaluate to true to display the message box "Good job"; it always evaluates to false. Any suggestions as to what the problem is?
Private Sub Form_Load()]
Dim x as Integer
Dim y as Integer
x=Int((10-0+1)*Rnd+0)
y=Int((10-0+1)*Rnd+0)
firstnum.value=x
secondnum.value=y
End Sub
Private Sub sumnum_LostFocus()
If sumnum.value=x+y Then
MsgBox ("Good job"
Else
MsgBox ("Bad job"
End If
End Sub
I am able to populate the firstnum and secondnum text boxes without any problem. My problem is that I can't get the if, then statement to evaluate to true to display the message box "Good job"; it always evaluates to false. Any suggestions as to what the problem is?