New Tricks

Menu
Powered by Blogger.

Making a Traffic Light in VB.Net

Firstly insert some commands and text boxes:
-command button 1 name it to "button1"
-command button 2 name it to "btn1"
-command button 3 name it to "btn2"
-command button 4 name it to "btn3"
-timer1
After insert these command press "F7" to go to code builder.

Secondly copy the code here and paste it in your code builder:
Sub red()
Me.btn1.BackColor = Color.Red
Me.btn2.BackColor = Color.DarkGray
Me.btn3.BackColor = Color.DarkGray
End Sub
Sub yellow()
Me.btn2.BackColor = Color.Yellow
Me.btn1.BackColor = Color.DarkGray
Me.btn3.BackColor = Color.DarkGray
End Sub
Sub blue()
Me.btn1.BackColor = Color.DarkGray
Me.btn2.BackColor = Color.DarkGray
Me.btn3.BackColor = Color.Blue
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Timer1.Start()
Me.Timer1.Interval = 100
Me.lbltext.Text = Microsoft.VisualBasic.Right(Me.lbltext.Text, Len(Me.lbltext.Text) - 1)
If Len(Me.lbltext.Text) >= 39 Then
Call blue()
Me.Button1.Text = Len(Me.lbltext.Text) - 9
ElseIf Len(Me.lbltext.Text) >= 10 Then
Call blue()
Me.Button1.Text = Len(Me.lbltext.Text) - 9
ElseIf Len(Me.lbltext.Text) >= 5 Then
Call yellow()
Me.Button1.Text = Len(Me.lbltext.Text) - 4
ElseIf Len(Me.lbltext.Text) >= 1 Then
Call red()
Me.Button1.Text = Len(Me.lbltext.Text)
ElseIf Me.lbltext.Text = "" Then
Me.lbltext.Text = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.btn1.BackColor = Color.DarkGray
Me.btn2.BackColor = Color.DarkGray
Me.btn3.BackColor = Color.DarkGray
Me.lbltext.Visible = False
End Sub
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
End Sub
Private Sub lbltext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbltext.Click
Me.Text = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
End Sub

Finally "Run" your application, for the faster the timer the smaller the interval.
if you want it slower use bigger interval value.

Share This:

Post Tags:

Ouk Chann

I'm Ouk Chann. A full time web designer. I enjoy to make modern template. I love create blogger template and write about web design, blogger. Now I'm working with Themeforest. You can buy our templates from Themeforest.

5 comments to ''Making a Traffic Light in VB.Net"

ADD COMMENT
  1. Can you make this program and give all source for me?

    ReplyDelete
    Replies
    1. those are the codes, you can only just create a form then paste those code then it will works

      Delete
    2. I'm very try to do it, but it not work.!

      Delete
  2. Hello! If you can please make it and send for me! Can tell me your phone number?

    ReplyDelete
  3. lbltext.Text is not defined is it? what is it?

    ReplyDelete

  • To add an Emoticons Show Icons
  • To add code Use [pre]code here[/pre]
  • To add an Image Use [img]IMAGE-URL-HERE[/img]
  • To add Youtube video just paste a video link like http://www.youtube.com/watch?v=0x_gnfpL3RM