Instructables
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
 
Remove these adsRemove these ads by Signing Up

Step 2: Buttons, Labels, Timer

Picture of Buttons, Labels, Timer
Now put in 4 Buttons, 8 Labels, 3 Numeric Up Down, 1 timer


Step 3: Label the Labels

Picture of Label the Labels
labels.png
Label the labels like this or code will not work and you would have to change some of it

label 1 = 00
label 2 = :
label 3 = 00
label 4 = :
label 5 = 00
label 6 = Hours
label 7 = Minutes
label 8 = Seconds

You Should also try to increase font to see the labels better


Step 4: Label the Buttons

Picture of Label the Buttons
Label the buttons like this :

Button1 = Set
Button2 = Start
Button3 = Reset
Button4 = Stop

Step 5: Set timer and NumericUpDown

Now For The Timer and the NumericUpDown Set The Maximum and Minimum Value like this :

NumericUpDown1 = Maximum 24, Minimum 0
NumericUpDown2 = Maximum 59, Minimum 0
NumericUpDown3 = Maximum 59, Minimum 0

Timer Interval = 1000

Step 6: The Code

Picture of The Code
Now For The Code:

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Label1.Text = NumericUpDown1.Text
        Label3.Text = NumericUpDown2.Text
        Label5.Text = NumericUpDown3.Text
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Label1.Text = "00"
        Label3.Text = "00"
        Label5.Text = "00"
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Timer1.Enabled = True
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Timer1.Enabled = False
    End Sub

    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 Then
            Label1.Text = Label1.Text - 1
            Label3.Text = 59
        End If
    End Sub
End Class

jd patel1 year 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.
:-)
rohit9011 year 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
sonal29131 year ago
How come the minutes are negetive?
00 : -1 : 48
and what's the use of numeric up down?
patsquare (author)  sonal29131 year 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
sonal29131 year 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.BSIT2 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~2 years ago
what size font is the 00:00:00 ?
patsquare (author)  ~KnexBuild~2 years ago
About 20 and bold
Thanks for the Reply.