By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,524 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,524 IT Pros & Developers. It's quick & easy.

Issue with My VB Program for Traffic Light Control System

P: 1
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.


Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Class Form1
  3.     Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
  4. End Sub
  5.  
  6.     Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
  7.  
  8.        OvalShape2.Visible = False
  9.         OvalShape1.Visible = True
  10.         OvalShape3.Visible = False
  11.  
  12.         If OvalShape1.Visible = True Then
  13.  
  14.             TextBox1.Text = "STOP!!!"
  15.         End If
  16.  
  17.     End Sub
  18.  
  19.     Private Sub OvalShape1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OvalShape1.Click
  20.  
  21.     End Sub
  22.  
  23.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  24.  
  25.       If OvalShape1.Visible Then
  26.             Timer1.Enabled = True
  27.             Timer1.Start()
  28.             Timer1.Interval = 10
  29.         ElseIf OvalShape2.Visible Then
  30.         End If
  31.         Timer1.Interval = 10
  32.  
  33.         If OvalShape3.Visible Then
  34.             Timer1.Interval = 10
  35.  
  36.         End If
  37.         Call Timer1.Start()
  38.     End Sub
  39. End Class
  40.  
  41.  
  42.  
  43.  

thank you!!
Apr 27 '13 #1
Share this Question
Share on Google+
2 Replies


100+
P: 158
Hey harryred7, its for 4 way road junction?
Apr 27 '13 #2

IronRazer
P: 83
Here is an example of a way to make it work.
Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.  
  3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4.         OvalShape_Red.Visible = False
  5.         OvalShape_Yellow.Visible = False
  6.         OvalShape_Green.Visible = True
  7.         TextBox1.Text = "Go"
  8.         Timer1.Interval = 60000
  9.         Timer1.Start()
  10.     End Sub
  11.  
  12.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  13.         Timer1.Stop()
  14.         If OvalShape_Green.Visible = True Then
  15.             OvalShape_Yellow.Visible = True
  16.             OvalShape_Green.Visible = False
  17.             TextBox1.Text = "Yield"
  18.             Timer1.Interval = 10000
  19.         ElseIf OvalShape_Yellow.Visible = True Then
  20.             OvalShape_Red.Visible = True
  21.             OvalShape_Yellow.Visible = False
  22.             TextBox1.Text = "Stop"
  23.             Timer1.Interval = 60000
  24.         ElseIf OvalShape_Red.Visible = True Then
  25.             OvalShape_Green.Visible = True
  26.             OvalShape_Red.Visible = False
  27.             TextBox1.Text = "Go"
  28.         End If
  29.         Timer1.Start()
  30.     End Sub
  31. End Class
  32.  
Apr 28 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.