Tuesday, December 21, 2010

Simple Stopwatch built in VB.NET [Open Source]

Stopwatch is a tool used to measure the length of time spent in the activity. Among others, the timing of testing tools that require time to millisecond accuracy in the laboratory, as well as on race neighborhood.

It was originally built for personal use when testing a device that relate to my daily work, but this time I hope can be useful not only for myself personally, as well as for others in need

Thefollowing is a stopwatch application interface  which is built using VB.Net, developed using Visual 2005, by using a form as interface design and equipped with several buttons and layout of the output value of the split time.

Dim startTime As DateTime
Private Sub BtnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGo.Click
If (Timer.Enabled) Then
BtnGo.Text = "Start"
startTime = DateTime.Now()
BtnGo.Text = "Stop"
End If
End Sub

Private Sub Timer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer.Tick
Dim span As TimeSpan = DateTime.Now.Subtract(startTime)
LabelAngka.Text = extZero(span.Hours.ToString) & ":" & extZero(span.Minutes.ToString) & ":" & _
LabelMilisecond.Text = span.Milliseconds
End Sub

Function extZero(ByVal binNum As String)
Dim ext As String = "0"
Dim HexToBin As String = ""
If binNum.Length < 2 Then Dim k As Integer = 1 Dim len As Integer = 2 - (binNum.Length + 1) For k = 1 To len ext = ext & "0" Next k HexToBin = ext + binNum ElseIf binNum.Length = 2 Then HexToBin = binNum End If Return HexToBin End Function Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click Timer.Enabled = False LabelAngka.Text = "00:00:00" LabelMilisecond.Text = "000" BtnGo.Text = "Start" MemoEdit1.Text = "" End Sub Private Sub BtnSplit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSplit.Click Dim nil As String = LabelAngka.Text & "." & LabelMilisecond.Text Dim daftar As String = MemoEdit1.Text If daftar = "" Then daftar = nil ElseIf daftar.Length > 1 Then
daftar = daftar + vbNewLine + nil
End If
MemoEdit1.Text = daftar
End Sub

And above is the source code used in this application, there are several procedures and functions used in this application.
That's all from me, with hopes to be useful to others. Thank you:)

No comments:

Post a Comment