Traffic Light is a road signal for directing vehicular traffic by means of colored lights, typically
red for stop,
green for go, and
yellow for proceed with caution. Also called stoplight, traffic signal.
In this tutorial, we will make a Traffic Light Program with the use only of shapes and timer.
Now, let's start this tutorial!
1. Let's start this tutorial by following the following steps in Microsoft Visual Basic 6.0: Open
Microsoft Visual Basic 6.0, click
Choose Standard EXE, and click
Open.
2. Next, add Three Shapes named as
Shape1 with fillcolor of
&H00004000&, Shape2 with fillcolor of
&H00000080&, and Shape3 with fillcolor of
&H0000C0C0&.Be sure that all of the shapes are having a
fillstyle of 0-solid. Add also a timer named
Timer1 and have an Interval of 3000 means a 3-second interval. You must design your interface like this:
3. Put this code in your code module.
Private Sub Form_Load()
Timer1.Enabled = True
Shape1.Visible = True
Shape2.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
We have created an event of the Timer for Timer1. We have created an If-Else statement that Shape1 is visible then only Shape2 will be the visible out of the three shapes.
Shapes provides a base class for shape elements, such as the Ellipse, Polygon, and Rectangle objects.
Timer.visible overrides the Visible property of the Control class to prevent this value from being set. If Shape2 is visible then only Shape3 will be the visible out of the three shapes.Otherwise, Shape1 will be visible if Shape3 is visible when the timer is ticking. In the form_load, we have created to enabled the time and displayed first the shape1 as Green color or 'Go'.
Timer.Enabled gets or sets a value that indicates whether the Timer control initiates a postback to the server after the number of milliseconds specified in the Interval property has elapsed.
Output:
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:
[email protected]
Add and Follow me on Facebook:
https://www.facebook.com/donzzsky
Visit and like my page on Facebook at:
https://www.facebook.com/BermzISware