stopwatch - sample program
VB.NET
Public
Class Form1Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
' global variables
Dim starttime, stoptime As Date Dim elapsedtime As TimeSpanPrivate Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
starttime = Now()
txtStart.Text = Format(starttime, "H:mm:ss")
'24-hour timetxtStop.Text = ""
txtElapsed.Text = ""
btnStop.Visible =
TruebtnStart.Visible =
False End Sub Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Clickstoptime = Now()
txtStop.Text = Format(stoptime, "H:mm:ss")
elapsedtime = stoptime.Subtract(starttime)
' convert elapsedtime/TimeSpan to String, then to Date w/CDate, then format it
txtElapsed.Text = Format(
CDate(elapsedtime.ToString), "H:mm:ss")btnStop.Visible =
FalsebtnStart.Visible =
True End SubEnd
Class