Pages

Monday, June 1, 2015

Visual Basic 6.0 Traffic lights

This program is going to simulate a  real traffic light at an interval of three seconds. 




In order to do this program we will need to insert 4 Shapes, 3 circles and 1 rectangle. 


To change the Shape's form we'll go to Properties > Shape 



Now to change the color of the Shapes you just need to go to Shape > Properties > Fill Style and change it to Solid.   



Then go to Properties > FillColor and choose the desire color. 



You will need to insert a Timer and assign it a value of 3000 in the Interval attribute which means 3 seconds. In order to do that you go to Properties > Interval and type 3000. 



The following is the whole program code: 



Private Sub Form_Load()
Shape2.Visible = True
Shape1.Visible = False
Shape3.Visible = False
End Sub

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

Note: It is necessary that the names of my Objects such as the Shapes and Timer be the same as yours in order to the program to work.