Option Explicit On
Public Class frmStopWatch
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents btnStart As System.Windows.Forms.Button
Friend WithEvents btnEnd As System.Windows.Forms.Button
Friend WithEvents btnExit As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents lblStart As System.Windows.Forms.Label
Friend WithEvents lblEnd As System.Windows.Forms.Label
Friend WithEvents lblElapsed As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.btnStart = New System.Windows.Forms.Button()
Me.btnEnd = New System.Windows.Forms.Button()
Me.btnExit = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.lblStart = New System.Windows.Forms.Label()
Me.lblEnd = New System.Windows.Forms.Label()
Me.lblElapsed = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'btnStart
'
Me.btnStart.Location = New System.Drawing.Point(16, 24)
Me.btnStart.Name = "btnStart"
Me.btnStart.TabIndex = 0
Me.btnStart.Text = "&Start Timing"
'
'btnEnd
'
Me.btnEnd.Location = New System.Drawing.Point(16, 112)
Me.btnEnd.Name = "btnEnd"
Me.btnEnd.TabIndex = 1
Me.btnEnd.Text = "&End Timing"
'
'btnExit
'
Me.btnExit.Location = New System.Drawing.Point(16, 208)
Me.btnExit.Name = "btnExit"
Me.btnExit.TabIndex = 2
Me.btnExit.Text = "E&xit"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(152, 24)
Me.Label1.Name = "Label1"
Me.Label1.TabIndex = 3
Me.Label1.Text = "Start Time"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(152, 112)
Me.Label2.Name = "Label2"
Me.Label2.TabIndex = 4
Me.Label2.Text = "End Time"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(144, 208)
Me.Label3.Name = "Label3"
Me.Label3.TabIndex = 5
Me.Label3.Text = "Elapsed Time(sec)"
'
'lblStart
'
Me.lblStart.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.lblStart.Location = New System.Drawing.Point(304, 24)
Me.lblStart.Name = "lblStart"
Me.lblStart.TabIndex = 6
'
'lblEnd
'
Me.lblEnd.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.lblEnd.Location = New System.Drawing.Point(304, 112)
Me.lblEnd.Name = "lblEnd"
Me.lblEnd.TabIndex = 7
'
'lblElapsed
'
Me.lblElapsed.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.lblElapsed.Location = New System.Drawing.Point(304, 208)
Me.lblElapsed.Name = "lblElapsed"
Me.lblElapsed.TabIndex = 8
'
'frmStopWatch
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(456, 262)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblElapsed, Me.lblEnd, Me.lblStart, Me.Label3, Me.Label2, Me.Label1, Me.btnExit, Me.btnEnd, Me.btnStart})
Me.ForeColor = System.Drawing.Color.Black
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.Name = "frmStopWatch"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Stopwatch Application"
Me.ResumeLayout(False)
End Sub
#End Region
Dim StartTime As Date
Dim EndTime As Date
Dim ElapsedTime As Double
Private Sub btnStart_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStart.Click
'Establish and print starting time
StartTime = Now
lblStart.Text = Format(StartTime, "hh:mm:ss")
lblEnd.Text = ""
lblElapsed.Text = ""
End Sub
Private Sub btnEnd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEnd.Click
'Find the ending time, compute the elapsed time
'Put both values in lable boxes
EndTime = Now
ElapsedTime = DateDiff(DateInterval.Second, StartTime, EndTime)
lblEnd.Text = Format(EndTime, "hh:mm:ss")
lblElapsed.Text = Format(ElapsedTime, "0")
End Sub
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
No one can help you unless you poost some code and describe the problem better.
--
Joe Fallon
I am a complete newbie to .net.
I have just built a simple Stopwatch Application but when I F5 to get things going I get this message popping up.
An unhandled exception of type 'System.ArithmeticException' occurred in system.drawing.dll
Additional information: Overflow or underflow in the arithmetic operation.
I am totally stumped. I sent this to my tutor who advised this works on his machine??
Please help I'm desperate..