by James Arnold (1 Submission)
Category: VB function enhancement
Compatability: VB Script
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)
This class module contains everything needed for creating a timer. It is very simple (18 lines), but provides millisecond accuracy using the GetTickCount API.
Assumes
To start the timer: MyTimer.StartTimer
To stop the timer: MyTimer.StopTimer
To read duration: MyTimer.ElapsedTime
Code Returns
Duration the timer has been running in milliseconds (divide by 1000 for seconds).
Side Effects
Due to the fact this is a class module the timer will continue to run even if a message box is displayed - the normal VB timer will pause when a messagebox is displayed. This can be an advantage or disadvantage, so take note.
API DeclarationsDim myTimer as timTimer
Set myTimer = New timTimer
Download Timer Class Module (2 KB)