This Traffic Light program is a Visual Basic program designed by Ankit Jain that works like the actual traffic light. It is a nice little program. In this program, you have to insert one timer and set its interval according to your wish. Here I set it to 5000, which is equivalent to 5 seconds. Next you insert three shapes and set their shape properties to circle and fill the colors. There it goes, your traffic light is working!
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
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