Re: Help with timers.
"CMiYC" <cmiyc@nowhere.com> wrote in message
news:pan.2003.11.10.19.11.25.920162@nowhere.com...[color=blue]
> On Mon, 10 Nov 2003 18:23:59 +0000, cassandra.flowers wrote:[color=green]
> > With 1 command button. Each time it is clicked it changes the backcolor
> > property of the circles. The problem with this, is that I don't know[/color][/color]
how to[color=blue][color=green]
> > make something change each time the command button is clicked:
> >
> > e.g. Red light
> > CLICK
> > Red & Amber light[/color][/color]
I have recently tackled the exact same 2 programs from a book called
"Computing Projects in Visual Basic" by D. Christopher. I'm in a good mood
so I'll post my two programs for you.
This one is for the Click event program:
Option Explicit
Dim counter As Integer
Private Sub Command1_Click()
counter = counter + 1
If counter = 5 Then
counter = counter - 4
End If
If counter = 1 Then
shpRed.BackColor = RGB(255, 0, 0)
shpAmber.BackColor = RGB(255, 255, 255)
shpGreen.BackColor = RGB(255, 255, 255)
ElseIf counter = 2 Then
shpAmber.BackColor = RGB(210, 100, 45)
ElseIf counter = 3 Then
shpGreen.BackColor = RGB(0, 140, 0)
shpRed.BackColor = RGB(255, 255, 255)
shpAmber.BackColor = RGB(255, 255, 255)
ElseIf counter = 4 Then
shpGreen.BackColor = RGB(255, 255, 255)
shpAmber.BackColor = RGB(210, 100, 45)
End If
End Sub
Private Sub Form_Load()
counter = 1
shpRed.BackColor = RGB(255, 0, 0)
shpAmber.BackColor = RGB(255, 255, 255)
shpGreen.BackColor = RGB(255, 255, 255)
End Sub
and this one is for the timer controlled program:
Option Explicit
Dim counter As Integer
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
counter = 1
shpRed.BackColor = RGB(255, 0, 0)
shpAmber.BackColor = RGB(255, 255, 255)
shpGreen.BackColor = RGB(255, 255, 255)
End Sub
Private Sub Timer1_Timer()
counter = counter + 1
If counter = 5 Then
counter = counter - 4
End If
If counter = 1 Then
shpRed.BackColor = RGB(255, 0, 0)
shpAmber.BackColor = RGB(255, 255, 255)
shpGreen.BackColor = RGB(255, 255, 255)
ElseIf counter = 2 Then
shpAmber.BackColor = RGB(210, 100, 45)
ElseIf counter = 3 Then
shpGreen.BackColor = RGB(0, 140, 0)
shpRed.BackColor = RGB(255, 255, 255)
shpAmber.BackColor = RGB(255, 255, 255)
ElseIf counter = 4 Then
shpGreen.BackColor = RGB(255, 255, 255)
shpAmber.BackColor = RGB(210, 100, 45)
End If
End Sub
To set the timer to an interval of 1000 open your form, select the timer
(which I assume you have placed on the form) then at the right of the screen
you can set the interval to 1000. Let me know how you get on.
PS. if you're gonna use my coding then remember to use the same names for
your lights i.e. shpGreen, shpRed, shpAmber |