VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A StopWatch

by Thejan J Rajapakshe (7 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Originally Published: Wed 3rd January 2007
Date Added: Mon 8th February 2021
Rating: (1 Votes)

A StopWatch

API Declarations


BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "CStopWatch"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False

Rate A StopWatch




' Win32 API declarations.
Private Declare Function timeBeginPeriod Lib "winmm.dll" (ByVal uPeriod As Long) As Long
Private Declare Function timeEndPeriod Lib "winmm.dll" (ByVal uPeriod As Long) As Long
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private Declare Function timeGetDevCaps Lib "winmm.dll" (lpTimeCaps As TIMECAPS, ByVal uSize As Long) As Long

' API Structure definitions.
Private Type TIMECAPS
   wPeriodMin As Long
   wPeriodMax As Long
End Type

' Set aside storage for private member variables.
Private m_StartTime As Long
Private m_PeriodMin As Long
Private m_PeriodMax As Long

' Desired timer resolution.
Private Const MINRES As Long = 1

' ********************************************
'  Initialize
' ********************************************
Private Sub Class_Initialize()
   ' Retrieve system timer resolution.
   Dim tc As TIMECAPS
   Call timeGetDevCaps(tc, Len(tc))
   m_PeriodMin = tc.wPeriodMin
   m_PeriodMax = tc.wPeriodMax
   
   ' Reprogram timer chip for 1ms resolution.
   Call timeBeginPeriod(MINRES)
   
   ' Store starting time.
   Call Me.Reset
End Sub

Private Sub Class_Terminate()
   ' Balance initial call, letting system know
   ' we no longer need higher-resolution.
   Debug.Print timeEndPeriod(MINRES)

Download this snippet    Add to My Saved Code

A StopWatch Comments

No comments have been posted about A StopWatch. Why not be the first to post a comment about A StopWatch.

Post your comment

Subject:
Message:
0/1000 characters