loading
Picture of Simple Timer in Visual Basic 2010
new project.png
In this instructable I will show you how to make a simple timer in Visual Basic 2010

It has : 4 Buttons
             8 Labels
             3 Numeric Up Down
             1 Timer

Step 1: New Project

Picture of New Project
new project.png
First Open Visual Basic and make a new project and select Windows Forms Application


 

I'm doing a project in Visual Studio 2013 is the pacman PictureBox need a code that moves by itself is the enemy and also need another code for the wall like the tego Labels will thank a lot

use timer. also X and Y possition = (integer for distance to move)

private sub tmr_tick(byval e as object).handles tmr_tick

'picture of pacMan named PICPM

dim POS as integer = 5

PICPM.left = POS

end sub

theres the base code just manipulate it to get the results required

jd patel2 years ago
Hello Rohit and sonal just use below code instead of given code in steps...it will work!!

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If label1.Text = "00" And label1.Text = "00" And label1.Text = "00" Then
Timer1.Enabled = False
End If
If label5.Text = 0 And label3.Text <> 0 Then
label5.Text = 59
label3.Text = label3.Text - 1
ElseIf label5.Text > 0 Then
label5.Text = label5.Text - 1
End If
If label3.Text = 0 And label1.Text <> 0 Then
label3.Text = 59
label1.Text = label1.Text - 1
End If
End sub

I Hope it will usefull to you.
:-)
rohit9012 years ago
Dsnt Work i put numbers in those boxes and set and start nothing works and my timer1 enabled = false when i make it true i can nt do anything i did nothing it Starts with negative numbers 0:-1 :59
sonal29132 years ago
How come the minutes are negetive?
00 : -1 : 48
and what's the use of numeric up down?
patsquare (author)  sonal29132 years ago
The numeric up down is for the user to set the desired hours, minutes, seconds. once he choses the desired time he presses the set button and then the start button to start counting down to 0.

"How come the minutes are negetive?
00 : -1 : 48 "
you probably didn't set the time first and it just counted down from 0
sonal29132 years ago
How come the minutes are negetive?
00 : -1 : 48
and what's the use of numeric up down?
I think I figured it out!

With what I had, when the hour changed, it would make the minutes 59 and then go to 58 changing the seconds to 59 directly afterwards. I changed the value of Label5.Text = 60

So:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Label5.Text = 0 Then
Label5.Text = 59
Label3.Text = Label3.Text - 1
ElseIf Label5.Text > 0 Then
Label5.Text = Label5.Text - 1
End If
If Label3.Text = 0 And Label1.Text > 0 And Label5.Text = 0 Then
Label1.Text = Label1.Text - 1
Label3.Text = 60
End If
If Label1.Text = 0 And Label3.Text = 1 And Label5.Text = 0 Then
Label5.Text = 59
Label3.Text = 0
End If
If Label1.Text = 0 And Label3.Text = 0 And Label5.Text = 0 Then
Timer1.Enabled = False
End If
End Sub
I think you have an error with the code under "Private Sub Timer1_Tick...".

I've been messing with the coding of this part for hours, but I still don't have any luck. They way you have it coded, when it reaches 1 minute, it starts making the hours negative. The timer never reaches 00:00:00.

Am I doing something wrong?
It's all just getting really jumbled now.
What I have been messing around with:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Label5.Text = 0 Then
Label5.Text = 59
Label3.Text = Label3.Text - 1
ElseIf Label5.Text > 0 Then
Label5.Text = Label5.Text - 1
End If
If Label3.Text = 0 And Label1.Text > 0 And Label5.Text = 0 Then
Label1.Text = Label1.Text - 1
Label3.Text = 59
End If
If Label1.Text = 0 And Label3.Text = 1 And Label5.Text = 0 Then
Label5.Text = 59
Label3.Text = 0
End If
If Label1.Text = 0 And Label3.Text = 0 And Label5.Text = 0 Then
Timer1.Enabled = False
End If
End Sub
jasmin.BSIT3 years ago
I am a beginner of Visual Basic Programming.. and I am confuse with this:
Label1.Text = NumericUpDown1.Text
Label3.Text = NumericUpDown2.Text
Label5.Text = NumericUpDown3.Text

I thought if you use label the code will be like this:
Label1.Caption=NumercicUpDown1.Caption
Label2.Caption=NumercicUpDown2.Caption
Label3.Caption=NumercicUpDown3.Caption

~KnexBuild~3 years ago
what size font is the 00:00:00 ?
patsquare (author)  ~KnexBuild~3 years ago
About 20 and bold
Thanks for the Reply.