34 Stopwatch using Timer in VB.NET

Design:


Timer in VB.NET


Code:

Public Class Form1

    Dim s As Integer = 0
    Dim m1 As Integer = 0
    Dim m As Integer = 0

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        m1 = m1 + 1
        Label1.Text = m & " : " & s & " : " & m1

        If m1 = 100 Then
            m1 = 0
            s = s + 1
            Label1.Text = m & " : " & s & " : " & m1

            If s = 60 Then
                s = 0
                m = m + 1
                Label1.Text = m & " : " & s & " : " & m1

                If m = 60 Then
                    Timer1.Stop()
                    m1 = 0
                    s = 0
                    m = 0
                    Label1.Text = m & " : " & s & " : " & m1
                End If
            End If
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Timer1.Stop()
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Timer1.Stop()
        m1 = 0
        s = 0
        m = 0
        Label1.Text = m & " : " & s & " : " & m1
    End Sub
End Class





Ouput:

Start:
Start Timer in VB.NET


Stop:




Reset:



Previous
Next Post »