VB2022 VB2019 VB6 VB Sample Code About Us

Traffic Light Simulator

This is a traffic light simulator that works like the actual traffic lights. It can be programmed fairly easily using Visual Basic 6. In this program, you have to insert one timer and set its interval to any figure. Here we set it to 3000, which is equivalent to 3 seconds. Next you insert three shapes and set their shape properties to circle and fill them with three colors, green, amber (or yellow) and red. Use the following code to set one color on and the other two colors off:

The Interface

The Code

Private Sub Timer1_Timer()
If Shape1.Visible Then

Shape2.Visible = True
Shape1.Visible = False
Shape3.Visible = False

ElseIf Shape2.Visible Then

Shape3.Visible = True
Shape2.Visible = False
Shape1.Visible = False


Shape1.Visible = True
Shape2.Visible = False
Shape3.Visible = False

End If

End Sub


Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy