VB2019 VB2017 VB2015 VB2013 VB2012 VB2010 VB2008 VB6 VB Sample Codes 中文VB 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

Else

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