ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   100ths of a second (https://www.excelbanter.com/excel-programming/406848-100ths-second.html)

TADropik

100ths of a second
 
is it possible to calculate 100ths or even 1000ths of a second in Excel.

I can calculate the time difference between 2 cells down to the second, but
is it possible to calculate down to the 100th of a second?

RB Smissaert

100ths of a second
 
Use the TimeGetTime API.

Option Explicit
Private lStartTime As Long
Private Declare Function timeGetTime Lib "winmm.dll" () As Long

Sub StartSW()
lStartTime = timeGetTime()
End Sub

Function StopSW(Optional bMsgBox As Boolean = True, _
Optional vMessage As Variant, _
Optional lMinimumTimeToShow As Long = -1) As Variant

Dim lTime As Long

lTime = timeGetTime() - lStartTime

If lTime lMinimumTimeToShow Then
If IsMissing(vMessage) Then
StopSW = lTime
Else
StopSW = lTime & " - " & vMessage
End If
End If

If bMsgBox Then
If lTime lMinimumTimeToShow Then
MsgBox "Done in " & lTime & " msecs", , vMessage
End If
End If

End Function


Sub test()

Dim i As Long

StartSW
For i = 1 To 10000000

Next i
StopSW

End Sub


RBS



"TADropik" wrote in message
...
is it possible to calculate 100ths or even 1000ths of a second in Excel.

I can calculate the time difference between 2 cells down to the second,
but
is it possible to calculate down to the 100th of a second?



TADropik

100ths of a second
 
That worked perfect.
Thank you for that.

Now if I can just get macros to run on my Cell Phone I have a nice little
stop watch to carry with me. ;-)


"RB Smissaert" wrote:

Use the TimeGetTime API.

Option Explicit
Private lStartTime As Long
Private Declare Function timeGetTime Lib "winmm.dll" () As Long

Sub StartSW()
lStartTime = timeGetTime()
End Sub

Function StopSW(Optional bMsgBox As Boolean = True, _
Optional vMessage As Variant, _
Optional lMinimumTimeToShow As Long = -1) As Variant

Dim lTime As Long

lTime = timeGetTime() - lStartTime

If lTime lMinimumTimeToShow Then
If IsMissing(vMessage) Then
StopSW = lTime
Else
StopSW = lTime & " - " & vMessage
End If
End If

If bMsgBox Then
If lTime lMinimumTimeToShow Then
MsgBox "Done in " & lTime & " msecs", , vMessage
End If
End If

End Function


Sub test()

Dim i As Long

StartSW
For i = 1 To 10000000

Next i
StopSW

End Sub


RBS



"TADropik" wrote in message
...
is it possible to calculate 100ths or even 1000ths of a second in Excel.

I can calculate the time difference between 2 cells down to the second,
but
is it possible to calculate down to the 100th of a second?





All times are GMT +1. The time now is 07:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com