Skip to content

Instantly share code, notes, and snippets.

@philo-ng
Created February 6, 2016 21:06
Show Gist options
  • Save philo-ng/6610f9e5e3f7acd6acff to your computer and use it in GitHub Desktop.
Save philo-ng/6610f9e5e3f7acd6acff to your computer and use it in GitHub Desktop.
Simple VB6 Stopwatch
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "Stopwatch"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private m_count As Long
Private m_last_os_tickcount As Long
Private m_elapsed_tick As Long
Private m_is_running As Boolean
Public Sub Reset()
m_count = 0
m_last_os_tickcount = 0
m_elapsed_tick = 0
m_is_running = False
End Sub
Private Sub Class_Initialize()
Reset
End Sub
Public Sub StartLab()
If m_is_running Then
Err.Raise vbObjectError, "StartLab", "Stopwatch is already started."
Else
m_is_running = True
m_last_os_tickcount = GetTickCount
End If
End Sub
Public Sub StopLab()
If m_is_running Then
m_count = m_count + 1
m_elapsed_tick = m_elapsed_tick + GetTickCount - m_last_os_tickcount
m_is_running = False
Else
Err.Raise vbObjectError, "StopLab", "Stopwatch is already stopped."
End If
End Sub
Public Property Get Average() As Double
If Count > 0 Then
Average = m_elapsed_tick / Count
Else
Err.Raise vbObjectError, "Average", "Stopwatch does not have data."
End If
End Property
Public Property Get Count() As Long
Count = m_count
End Property
Public Sub Show()
MsgBox "Avgerage = " & Average, vbInformation, "Count = " & Count
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment