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]