Visual Basic | Traffic signal using if-else loop - wordsclank.in

Saturday 8 April 2017

Visual Basic | Traffic signal using if-else loop

Hi guys.
We have already discuss piggy bank  and we are now going to discus another vb program i.e, Traffic Signals and we are sure it will be more fun.

So let start with the form design first.
traffic light,Visual Basic,






Here we have taken a timer and three circular shapes from the shape tool option.
Next arrange them in a sequencing meaner. Change the property of backstyle to opaque
and add color to the shapes.Then add a timer to the form.

Changed property:
   shape1:
      backstyle   : opaque
      backcolor   :red
   shape2:
       backstyle  :opaque
       backcolor  :yellow
  shape3:
       backstyle  :opaque
       backcolor  :green
 Timer1:
       interval  :3000






Moving to the source code
        We will write the code under the timer1's  timer event.


SOURCE CODE

Private Sub Timer1_Timer()
 If shape1.Visible = True Then

       shape2.Visible = True

       shape3.Visible = False

       shape1.Visible = False

   Else If shape2,Visible = True Then

        shape3.Visible = True

        shape1.Visible = False

        shape2.Visible = False

  Else shape2.Visible = False

        shape3.Visible = False

        shape1.Visible = True

  End If

End Sub






NOTE:

1. In the interval property of the timer we have given 3000. Here 1000 means 1 sec time interval.

2.The program uses If - Else loop statement.

3.The properties are changed through property toolbar.

Thanks for reading.If you have any doubt comment on the comment section, w|e will be vary happy to help you..







No comments:

Post a Comment