Sunday, May 25, 2014

An Application Package on Traffic Management System (TMS) ~~ VisualBasic Code Snippet + GUI Design



Traffic Light Interface Design


-: Tools Used : - 
1. label as Counter
2. OvalShape as Redlight, GreenLight and YellowLight
3. 2 Timer controls as Timer and TimerNext

Source code for "Traffic Light Interface Design"

Public Class Form2  'Class Declaration

    Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick

        Counter.Text = Counter.Text - 1
        If Counter.Text = 12 Then
            Counter.ForeColor = Color.Yellow
            YellowLight.BackColor = Color.Yellow
            RedLight.BackColor = Color.Black

        ElseIf Counter.Text = 0 Then
            GreenLight.BackColor = Color.Green
            Counter.ForeColor = Color.Green
            YellowLight.BackColor = Color.Black

            Timer.Enabled = False
            Counter.Text = 70
            TimerNext.Enabled = True

        End If
    End Sub

    Private Sub TimerNext_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerNext.Tick

        Counter.Text = Counter.Text - 1
        If Counter.Text = 12 Then
            Counter.ForeColor = Color.Red

        ElseIf Counter.Text = 0 Then
            GreenLight.BackColor = Color.Black
            Counter.ForeColor = Color.Red
            RedLight.BackColor = Color.Red

            TimerNext.Enabled = False
            Counter.Text = 70
            Timer.Enabled = True

        End If
    End Sub

End Class