Issue with My VB Program for Traffic Light Control System

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harryred7
    New Member
    • Apr 2013
    • 1

    #1

    Issue with My VB Program for Traffic Light Control System

    Hi

    Question- I am currently writing a VB program for a traffic light control system. It nothing too robust nor with any microprocessors/sensors.
    i am using a Timer to control when the lights turns Red/Amber/Green which depicts the Conventional traffic light system of Stop/Ready or Wait/Go Respectively. so far i have been able to make my Light Signals come on and off but am yet to implement my Timers.

    here below is a scenario of how i would like ti see it work

    If Red is Visible then countdown for about 120seconds and switch to Amber for about 10 seconds and then back to 120seconds for Green.


    Code:
    Public Class Form1
        Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
    End Sub
    
        Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
           
           OvalShape2.Visible = False
            OvalShape1.Visible = True
            OvalShape3.Visible = False
    
            If OvalShape1.Visible = True Then
    
                TextBox1.Text = "STOP!!!"
            End If
    
        End Sub
    
        Private Sub OvalShape1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OvalShape1.Click
    
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            
          If OvalShape1.Visible Then
                Timer1.Enabled = True
                Timer1.Start()
                Timer1.Interval = 10
            ElseIf OvalShape2.Visible Then
            End If
            Timer1.Interval = 10
    
            If OvalShape3.Visible Then
                Timer1.Interval = 10
    
            End If
            Call Timer1.Start()
        End Sub
    End Class

    thank you!!
  • vijay6
    New Member
    • Mar 2010
    • 158

    #2
    Hey harryred7, its for 4 way road junction?

    Comment

    • IronRazer
      New Member
      • Jan 2013
      • 83

      #3
      Here is an example of a way to make it work.
      Code:
      Public Class Form1
      
          Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
              OvalShape_Red.Visible = False
              OvalShape_Yellow.Visible = False
              OvalShape_Green.Visible = True
              TextBox1.Text = "Go"
              Timer1.Interval = 60000
              Timer1.Start()
          End Sub
      
          Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
              Timer1.Stop()
              If OvalShape_Green.Visible = True Then
                  OvalShape_Yellow.Visible = True
                  OvalShape_Green.Visible = False
                  TextBox1.Text = "Yield"
                  Timer1.Interval = 10000
              ElseIf OvalShape_Yellow.Visible = True Then
                  OvalShape_Red.Visible = True
                  OvalShape_Yellow.Visible = False
                  TextBox1.Text = "Stop"
                  Timer1.Interval = 60000
              ElseIf OvalShape_Red.Visible = True Then
                  OvalShape_Green.Visible = True
                  OvalShape_Red.Visible = False
                  TextBox1.Text = "Go"
              End If
              Timer1.Start()
          End Sub
      End Class

      Comment

      Working...