Visual Basic Explorer
Visual Basic Explorer
 Navigation
 Home


 Coding
 Source Code

 FAQ Center

 VB Tips

 Downloads

 ToolBox

 Tutorials

 VB Games

 VB News

 VB Award

 VB Forums



 Affiliates
 Planet Source Code

 Rent a Coder

 DirectX4VB


 Misc
 Search

 Feedback

 Advertise

 About


Need to hire
a VB coder?

Please support our sponsor:

 Home 
 Site Map 
 Forums 
 News 
 Feedback 

 

'-------------------------------------
'Author: Anne-Marie Wright
'Email: anne.wright@ukonline.co.uk
'Added: 26-June-2000
'-------------------------------------
'Program: STOPWATCH2.ZIP
'-------------------------------------
'Description: What I have done is create a small
'crude Stopwatch application the first one - stopwatch.zip
'does not use the timer control it is purely using the
'system clock. Stopwatch2.zip (also on the downloads page)
'is an enhanced version of the first one which
'uses both the system clock and a timer.
'
'Also in the example is how to create control arrays
'at run-time. I hope this is of some use.
'-------------------------------------
Option Explicit

 
Dim timStart As Date
Function TimeDifference(timLap As Date) As String

TimeDifference = Minute(timLap - timStart) & ":" & Right("00" & Second(timLap - timStart), 2)

 
End Function

 
Private Sub cmdLap_Click()
On Error GoTo cmdLap_Error
Dim timLap As Date
Dim strTime As String
Dim Index As Integer

If Left(cmdLap.Caption, 3) = "Lap" Then
If cmdLap.Tag = 5 Then
MsgBox "Only 5 lap times are allowed"
Exit Sub
End If
timLap = Time
lblLap(cmdLap.Tag).Caption = "Lap " & cmdLap.Tag + 1 & ": " & TimeDifference(timLap)
cmdLap.Tag = cmdLap.Tag + 1
cmdLap.Caption = "Lap " & cmdLap.Tag + 1
Else
cmdLap.Tag = 0
lblTime.Caption = "0"
For Index = lblLap.lbound To lblLap.UBound
lblLap(Index).Caption = ""
Next Index
Timer1.Enabled = True
End If
cmdLap_Exit:
Exit Sub
cmdLap_Error:
Select Case Err.Number
Case 340
Load lblLap(cmdLap.Tag)
lblLap(cmdLap.Tag).Left = 3780
lblLap(cmdLap.Tag).Top = lblLap(cmdLap.Tag - 1).Top + lblLap(cmdLap.Tag - 1).Height + 20
lblLap(cmdLap.Tag).Visible = True
Resume
Case Else
MsgBox "Error " & Err.Number & " - " & Err.Description
Resume cmdLap_Exit
End Select
End Sub

 

 
Private Sub cmdStart_Click()
Dim timEnd As Date

If cmdStart.Caption = "Start Timing" Then
'Start the clock
timStart = Time
cmdStart.Caption = "Stop Timing"
cmdLap.Caption = "Lap " & cmdLap.Tag + 1
lblTime.Caption = "Running"
Else
'Stop the clock
timEnd = Time
cmdStart.Caption = "Start Timing"
cmdLap.Caption = "Reset"
lblTime.Caption = TimeDifference(timEnd)
Timer1.Enabled = False
End If
End Sub

 

 
Private Sub Form_Load()
lblVersion.Caption = "Version: " & App.Major & "." & App.Minor & "." & App.Revision
End Sub

 

 
Private Sub Timer1_Timer()
Timer1.Enabled = False
If cmdStart.Caption = "Start Timing" Then
lblTime.Caption = Time
Else
lblTime.Caption = TimeDifference(Time)
End If
Timer1.Enabled = True
End Sub

 

 

 

 
'-------------------------------------
'Burt Abreu
'http://www.VBExplorer.com
'-------------------------------------

 


Downloads

In IE right-click and select 'Save Target As...' or in Netscape right-click and select 'Save Link As...'

 

View Plain Text View Plain Text
Download Demo Project Download Demo Project
View Code Online Not Available





Home | About | What's New | Source Code | FAQ | Tips & Tricks | Downloads | ToolBox | Tutorials | Game Programming | VB Award | Search | VB Forums | Feedback | VBNews | Copyright & Disclaimer | Advertise | Privacy Policy |

Quick searches: Site Search | Advanced Site Search 

Copyright 2002 by Exhedra Solutions, Inc.
By using this site you agree to its terms and conditions
VB Explorer and VBExplorer.com are trademarks of Exhedra Solutions, Inc.