Roberto
Member
- Joined
- Mar 9, 2006
- Messages
- 16
- Programming Experience
- Beginner
Hi i can't work out how to solve this and am at my wits end with it. I'm experimenting with a times table tester that asks the user a question, waits 2 seconds then gives the answer and validates it against the user entered value. This i've got working, but i want to then clear all the boxes and repeat the process again so the user is asked ten questions in a row without having to click start again. Still being new to VB.net i've run out of ideas. Thanks in advance for any help on this.
VB.NET:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1 = New Timer()
Timer1.Interval = 2000
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'This happens after timer runs it's set interval
'Validates user answer, txtResult box not visible to user
txtResult.Text = Val(txtNumber1.Text) * Val(txtNumber2.Text)
If txtResult.Text = txtUserResult.Text Then
txtFeedback.Text = "CORRECT"
txtFeedback.BackColor = Color.LightBlue
Else
txtFeedback.Text = "WRONG!"
txtFeedback.BackColor = Color.Red
End If
If txtUserResult.Text = "" Then
txtFeedback.Text = "OUT OF TIME"
txtFeedback.BackColor = Color.Red
End If
Timer1.Stop()
btnStart.Enabled = True
End Sub
Private Sub btnStart_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
'These events happen whilst timer1 runs
Timer1.Start()
' Clears boxes
txtResult.Text = ""
txtFeedback.Text = ""
txtFeedback.BackColor = Color.White
txtUserResult.Text = ""
txtNumber1.Text = ""
txtNumber2.Text = ""
'disable the start button
btnStart.Enabled = False
txtUserResult.Focus()
'generate numbers
If txtTitle.Text = "2 Times Table" Then
txtNumber1.Text = (2)
txtNumber2.Text = (Int(Rnd() * 12))
End If
End Sub