Traffic Light Program in VB6

Submitted by: 
Visitors have accessed this post 18885 times.

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.

  1. Private Sub Form_Load()
  2. Timer1.Enabled = True
  3. Shape1.Visible = True
  4. Shape2.Visible = False
  5. Shape3.Visible = False
  7. End Sub
  8. Private Sub Timer1_Timer()
  9. If Shape1.Visible Then
  11. Shape2.Visible = True
  12. Shape1.Visible = False
  13. Shape3.Visible = False
  15. ElseIf Shape2.Visible Then
  17. Shape3.Visible = True
  18. Shape2.Visible = False
  19. Shape1.Visible = False
  21. Else
  23. Shape1.Visible = True
  24. Shape2.Visible = False
  25. Shape3.Visible = False
  27. End If
  29. 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.


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:

Visit and like my page on Facebook at:

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.