I'm trying to make VBA's GetTickCount work so that I can see the runtime of code, but it doesn't have to be super accurate.
The following bit of code works good but I need a few changes and can't work out how to achieve this.
#If Win64 Then
Public Declare PtrSafe Function GetTickCount Lib "kernel32" () As Long
#Else
Public Declare Function GetTickCount Lib "kernel32" () As Long
#End If
' Get first tickcount, start of code
t1 = GetTickCount
'Do stuff here
'#############
'#############
'#############
' Get second tickcount, end of code
t2 = GetTickCount
' Compare tickcounts
If t2 < t1 Then
' If t2 is smaller than t1 then the tickcount has been reset, use reset tick value + t2 - t1
Application.StatusBar = "VBA Code Runtime ms: " & (4294967295# + t2) - t1
Else
' If t2 is bigger than t1 then just use t2 - t1
Application.StatusBar = "VBA Code Runtime ms: " & t2 - t1
End If
I want the runtime to be presented in the following ways.
- If runtime under 1 second it should be presented in milliseconds. Example: 180 milliseconds
- If runtime under 1 minute but more than 1 second it should be presented in seconds (no milliseconds). Example: 30 seconds
- If runtime OVER 1 minute but less than 1 hour it should be presented in minute second. Example: 1 minute, 30 seconds
- If runtime OVER 1 hour it should be presented in hours, minutes and second Example: 2 hours, 1 minute, 30 seconds
How would I achieve this, any help would be much appreciated.
Bookmarks