Visual Basic Core Snippet Routines
GetTickCount
         
              
   Retrieves the number of milliseconds that have elapsed since the system was started. When combined with a start point, provides a means to time a method's performance.        
           Updated:   Monday December 26, 2011   
click to copy code:  



   Applies to:   VB4-32, VB5, VB6   
OS restrictions:   None  
 Code Snippet
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce 
'               or publish this code on any web site,
'               online service, or distribute as source 
'               on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private tstart As Single
  
Private Enum ElapsedTimeType
  ttMilliseconds = 1
  ttSeconds = 2
  ttMinutes = 3
End Enum


Private Function GetElapsedTime(dwTimeType As ElapsedTimeType) As Single

   Dim divisor As Long

   Select Case dwTimeType
      Case ttMilliseconds: divisor = 1
      Case ttSeconds:      divisor = 1000
      Case ttMinutes:      divisor = 60000      
   End Select
   
   GetElapsedTime = (GetTickCount() - tstart) / divisor

End Function


Private Sub Form_Load()

  'Assign the current tick count
  'as the tick start point. Failure
  'to do this will return the number
  'of ticks since Windows was last
  'rebooted. (Note: elapsed time is
  'stored as a DWORD value in Windows.
  'Therefore, the time will wrap around
  'to zero if the system is run continuously
  'for 49.7 days. If a higher resolution
  'timer is required, use a multimedia
  'or high-resolution timer.
   tstart = GetTickCount()
                                    
End Sub

 Calling Syntax
   Print FormatNumber(GetElapsedTime(ttMilliseconds), 0) & "milliseconds"
           Print FormatNumber(GetElapsedTime(ttSeconds), 2) & " seconds"
           Print FormatNumber(GetElapsedTime(ttMinutes), 2) & " minutes"
FormatNumber is available in VB5/VB6 only. Format$ can also be used.

 Comments / Related
demo in use:   FindFirstFile: Changing File and/or Folder Attributes Recursively
FindFirstFile: Recursive File Search for Single or Multiple File Types (minimal code)

FindFirstFile: Performance Comparison - FSO vs. API
  
Related:      

 
 

PayPal Link
Make payments with PayPal - it's fast, free and secure!

 
 
 
 

Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy

 

Hit Counter