Skip to content

VBMAN.TimeUse - Timer Object

Overview

VBMAN.TimeUse provides simple code execution time measurement functionality, implemented using the GetTickCount API.

Core Features

  • Easy to Use: Start timing and display elapsed time
  • Custom Output Format: Support custom output text template

Methods

Start

Start timing

vb
Public Sub Start()

Example:

vb
VBMAN.TimeUse.Start

Show

Display elapsed time

vb
Public Function Show(Optional Txt As String = "Elapsed: {*} ms") As Variant

Parameters:

  • Txt - Output text template, use {*} as elapsed time placeholder

Returns: Formatted string

Example:

vb
' Default format
Debug.Print VBMAN.TimeUse.Show
' Output: Elapsed: 123 ms

' Custom format
Debug.Print VBMAN.TimeUse.Show("Execution time: {*} ms")
' Output: Execution time: 123 ms

Comprehensive Examples

Example 1: Measure Code Execution Time

vb
Private Sub TestPerformance()
    ' Start timing
    VBMAN.TimeUse.Start
    
    ' Code to measure
    Dim i As Long
    Dim sum As Long
    For i = 1 To 1000000
        sum = sum + i
    Next i
    
    ' Display elapsed time
    Debug.Print VBMAN.TimeUse.Show("Loop calculation time: {*} ms")
End Sub

Example 2: Function Execution Time Recording

vb
Private Sub ProcessData()
    VBMAN.TimeUse.Start
    
    ' Data processing logic
    Call LoadDataFromDatabase
    Call ProcessRecords
    Call SaveResults
    
    ' Record to log
    VBMAN.Logs.DataLine VBMAN.TimeUse.Show("Data processing completed, time: {*} ms"), "Performance Stats"
End Sub

Notes

  • Uses GetTickCount API, precision is millisecond level
  • Timer restarts timing after calling Start
  • For higher precision, recommend using QueryPerformanceCounter API

VB6 and LOGO copyright of Microsoft Corporation