Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

How to Make a Simple Stopwatch

Open up visual basic and make a windows form named anything you want.

The GUI:

Insert 3 buttons, and a label.

Name one button's text: Start

Second Button: Pause

Third Button: Stop

Name the label: 0.00

Insert a timer make it not enabled and a interval of: 1

The Code:

Double Click the start button:

Turn on the timer

Code
Timer1.Enabled = True

Double click the pause button and turn off timer

Code
Timer1.Enabled = False

Double Click Stop Button and turn off timer and reset the label to 0.0

Code
Timer1.Enabled = False
Label1.Text = 0.0

Double click the timer and make the label tick by 0.01

Code
Label1.Text = Label1.Text + 0.01

Final Code:

Code
Public Class Form1

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Timer1.Enabled = True
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Enabled = False
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Enabled = False
        Label1.Text = 0.0
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = Label1.Text + 0.01
    End Sub
End Class

With every day passing by, I lose a little bit more faith in this section...
You know there is a stopwatch class with various methods and properties to measure elapsed time, right? Heed my warning, continue flooding the .NET section with ridiculous (poor) tutorials like this and your rep will sink to red my friend. That's a fact, not a threat. It's happened before.
(Jan 2, 2015 06:36 PM)Odus Wrote:  You know there is a stopwatch class with various methods and properties to measure elapsed time, right? Heed my warning, continue flooding the .NET section with ridiculous (poor) tutorials like this and your rep will sink to red my friend. That's a fact, not a threat. It's happened before.

I understand that your just correcting me but your just being a jerk now... All I am doing is trying to help geeze.
(Jan 2, 2015 06:38 PM)CodeBinary Wrote:  I understand that your just correcting me but your just being a jerk now... All I am doing is trying to help geeze.

Code
Label1.Text = Label1.Text + 0.01

Trying to help, right...
Like Odus said, there is a stop watch class for this specific purpose. Using a timer is not the most ideal.

Dim sw As New Stopwatch
sw.Start()

Messagebox.Show(sw.Ellap...)

yeah u get the idea.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Java] by deadsh0tJun 12, 2019 06:27 AM 0 115 Jun 12, 2019 06:27 AM
Last Post: deadsh0t
[.NET] by VmX5Sep 9, 2015 08:33 AM 5 373 Sep 9, 2015 08:33 AM
Last Post: asdfghjklwertyuio345678
[.NET] by webwarlock72May 30, 2015 03:39 PM 4 118 May 30, 2015 03:39 PM
Last Post: paquiton96