I'm at a beginner level using VB.Net, 2008
I'm doing a small project to learn how to control timers.
I have a Button click event which, in its sub, starts seven timers
Each timer has its own sub that, in their subs, makes some color changes.
I want the program to
sequence through these seven timers/colors – in order – up to 10 times and I do not understand how to get back to and start the click event again in code.
Presently the program basically
runs through the cycles properly but with no control over how many cycles can be performed.
How do I get the program to loop through starting at the click event ONLY the 10 times (see shortened code below) and QUIT cycling without quitting the program? (Other Buttons will be added for other events.)
Form Load
Set all seven timers Intervals individually
Button Click
Enable all seven timers individually
Private Sub tmr1
Change Panel1 BackColor
Private Sub tmr2
Panel1 BackColor change back to Transparent
Change Panel2 BackColor
Private Sub tmr3
Panel2 BackColor change back to Transparent
Change Panel3 BackColor
Private Sub tmr4
Panel3 BackColor change back to Transparent
Change Panel4 BackColor
Private Sub tmr5
Panel4 BackColor change back to Transparent
Change Panel5 BackColor
Private Sub tmr6
Panel5 BackColor change back to Transparent
Change Panel6 BackColor
Private Sub tmr7
Panel6 BackColor change back to Transparent
Disable all timers individually
Reset all timer intervals individually
Enable all timers individually
Private Sub tmr 7 resets the timers and recycles the run through the timers, but, I would like to continue the code here to control the number of times it does cycle. I could not control it with a DO statement. Any ideas?
Thanks - JG

Kirtan PatelRank #292 · 8.6K reputationPosted Oct 17, 2009, 12:54 AM EDT
Friend ,
Here is Code you wanted :)
dont forget to mark "do you like this answer" if my answer helped you :)
Private counter1 As Integer = 0, counter2 As Integer = 0, counter3 As Integer = 0, counter4 As Integer = 0, counter5 As Integer = 0, counter6 As Integer = 0, _ counter7 As Integer = 0 Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) 'Set Interval of All the Timers timer1.Interval = 1000 timer2.Interval = 2000 timer3.Interval = 1500 timer4.Interval = 500 timer5.Interval = 700 timer6.Interval = 300 timer7.Interval = 3000 End Sub Private Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) 'Change the Color of Panel and Count the iteration panel1.BackColor = Color.Red counter1 += 1 End Sub Private Sub timer2_Tick(ByVal sender As Object, ByVal e As EventArgs) panel1.BackColor = Color.Green counter2 += 1 End Sub Private Sub timer3_Tick(ByVal sender As Object, ByVal e As EventArgs) panel1.BackColor = Color.Blue counter3 += 1 End Sub Private Sub timer4_Tick(ByVal sender As Object, ByVal e As EventArgs) panel1.BackColor = Color.Yellow counter4 += 1 End Sub Private Sub timer5_Tick(ByVal sender As Object, ByVal e As EventArgs) panel1.BackColor = Color.Violet counter5 += 1 End Sub Private Sub timer6_Tick(ByVal sender As Object, ByVal e As EventArgs) panel1.BackColor = Color.Wheat counter6 += 1 End Sub Private Sub timer7_Tick(ByVal sender As Object, ByVal e As EventArgs) panel1.BackColor = Color.Transparent counter7 += 1 End Sub Private Sub btnStart_Click(ByVal sender As Object, ByVal e As EventArgs) 'Start All timers At once timer1.Enabled = True timer2.Enabled = True timer3.Enabled = True timer4.Enabled = True timer5.Enabled = True timer6.Enabled = True timer7.Enabled = True End Sub Private Sub btnStop_Click(ByVal sender As Object, ByVal e As EventArgs) 'Stop the timer On CLicing Stop Button timer1.Enabled = False timer2.Enabled = False timer3.Enabled = False timer4.Enabled = False timer5.Enabled = False timer6.Enabled = False timer7.Enabled = False 'Show Number of Count on Timer Stop label1.Text = "Timer 1:" & counter1.ToString() label2.Text = "Timer 2:" & counter2.ToString() label3.Text = "Timer 3:" & counter3.ToString() label4.Text = "Timer 4:" & counter4.ToString() label5.Text = "Timer 5:" & counter5.ToString() label6.Text = "Timer 6:" & counter6.ToString() label7.Text = "Timer 7:" & counter7.ToString() End Sub