For...Next + Timer Issue

Roberto

Member
Joined
Mar 9, 2006
Messages
16
Programming Experience
Beginner
Hi, trying to get my For...Next loop to work, what am i not doing? I don't have any build errors but nothing happens. Still a newbie to VB.Net and struggling to understand loads. Would appreciate anyone's help on this.

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load[/SIZE]
[SIZE=2]Timer1 = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Timer()[/SIZE]
[SIZE=2]Timer1.Interval = 8000[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Timer1_Tick([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] Timer1.Tick[/SIZE]
[COLOR=red][SIZE=2]Dim[/SIZE][SIZE=2] Count [/SIZE][SIZE=2]As[/SIZE][SIZE=2]Integer[/SIZE][/COLOR]
[COLOR=red][SIZE=2]For[/SIZE][SIZE=2] Count = 1 [/SIZE][SIZE=2]To[/SIZE][SIZE=2] 10 [/SIZE][SIZE=2]Step[/SIZE][SIZE=2] 1[/SIZE][/COLOR]
 
[SIZE=2][COLOR=#008000]'Runs 8 seconds after timer.Start()[/COLOR][/SIZE]
[SIZE=2]txtResult.Text = Val(txtNumber1.Text) * Val(txtNumber2.Text)[/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtResult.Text = txtUserResult.Text [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]txtFeedback.Text = [/SIZE][SIZE=2][COLOR=#800000]"CORRECT"[/COLOR][/SIZE]
[SIZE=2]txtFeedback.BackColor = Color.LightBlue[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]txtFeedback.Text = [/SIZE][SIZE=2][COLOR=#800000]"WRONG!"[/COLOR][/SIZE]
[SIZE=2]txtFeedback.BackColor = Color.Red[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtUserResult.Text = [/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]txtFeedback.Text = [/SIZE][SIZE=2][COLOR=#800000]"OUT OF TIME"[/COLOR][/SIZE]
[SIZE=2]txtFeedback.BackColor = Color.Red[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=red]Next[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#008000]'reset timer/button for next round[/COLOR][/SIZE]
[SIZE=2]Timer1.Stop()[/SIZE]
[SIZE=2]btnStart.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] btnStart_Click_1([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] btnStart.Click[/SIZE]
 
[SIZE=2][COLOR=#008000]' Clears boxes for next go[/COLOR][/SIZE]
[SIZE=2]txtResult.Text = [/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE]
[SIZE=2]txtFeedback.Text = [/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE]
[SIZE=2]txtFeedback.BackColor = Color.White[/SIZE]
[SIZE=2]txtUserResult.Text = [/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#008000]'generate numbers[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtTitle.Text = [/SIZE][SIZE=2][COLOR=#800000]"2 Times Table"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]txtNumber1.Text = (2)[/SIZE]
[SIZE=2]txtNumber2.Text = (Int(Rnd() * 12))[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#008000]'start timer[/COLOR][/SIZE]
[SIZE=2]Timer1.Start()[/SIZE]
 
[SIZE=2][COLOR=#008000]'disable the start button[/COLOR][/SIZE]
[SIZE=2]btnStart.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE]
[SIZE=2]txtUserResult.Focus()[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
What is it exactly that you are trying to do? I specificly dont understand the porint of the:

VB.NET:
Dim Count AsInteger
For Count = 1 To 10 Step 1

[...]

Next[SIZE=2][COLOR=red][/COLOR][/SIZE]

I think that is the part you are thinking will do something that it will not, but I'm not sure what it is that you expect it to do. If you can clarify that, I'm sure we can help you understand how to do it.
 
I have three textboxes, when the Start button is pressed the program throws a multiplication question at the user. This is linked to a timer that waits and answers the question, then checks it against the user's answer. When clicking start i wanted the process to run ten times i.e. ten questions to be asked. Hope this clarifies.
 
so there's 10 questions needing 3 textbox's each and each question is asked one at a time?

just do that in the timer, no need for the For loop in the timer's tick event
 
Back
Top