How Do I use milliseconds in OnTIme function.
VBA timer works in seconds, is there any fast way to get .1 sec or 0.05 sec....
How Do I use milliseconds in OnTIme function.
VBA timer works in seconds, is there any fast way to get .1 sec or 0.05 sec....
Hello Slyone2,
The Application.OnTime method is limited to 1 second minimum. To get finer timer resolution would require using an API timer. I would advise against it due to its instability in the Office environment.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
I have this from excel to measure calcs.....
Can it be modified for Appliation.OnTime![]()
Please Login or Register to view this content.
Is that the same for Application.Wait ???
Hello Slyone2,
You don't need to use the API calls. VBA returns the tick count through the Timer function. The fastest the Application.OnCall event can fire is every 1 second. The tick count will have increased by 1 second or 1000 milliseconds by the time the Application.OnTime event is fired.
Here is how to measure a calculation...
![]()
Please Login or Register to view this content.
Timer and GetTickCount are different.
Timer returns the number of seconds since midnight as a Single; on PCs, you get about 10ms precision.
GetTickCount returns the number of milliseconds since restart as an unsigned 32-bit integer, which wraps after ~49 days.
Entia non sunt multiplicanda sine necessitate
On precision, on Xp 64 is it the same?
And what about linux?
Hello Slyone2,
I came across this timer for VBA that may work for you and it is free.
Karl E. Peterson's VBA TimerObj
'Put this on the Form w/ Command Button and text box...
'*********************************************************************************
Private Sub CommandButton1_Click()
Dim StartTime As Long
Dim NextFrameTime As Long
timeBeginPeriod 1 'switch resolution to 1 ms
Do
StartTime = timeGetTime
NextFrameTime = Interval + StartTime
Text3.Text = Format(Now, "HH:nn:ss") & "." & Right(Format(Timer, "#0.00"), 2) '---> This will display time with milliseconds...
DoEvents
Do While timeGetTime < NextFrameTime
DoEvents
If timeGetTime + 5 < NextFrameTime Then
Sleep NextFrameTime - (timeGetTime + 5)
End If
Loop
Loop
End Sub
'*************************************************************************
'Create a module and put the code below....
'********************************************************************************
Public Declare Function timeGetTime Lib "winmm.dll" () As Long
Public Declare Function timeBeginPeriod Lib "winmm.dll" (ByVal uPeriod As Long) As Long
'16-bit programs must use MMSYSTEM.DLL instead of WINMM.DLL
Public Declare Sub Sleep Lib "kernel32" (ByVal uDuration As Long)
'16-bit programs cannot do a "Sleep", just omit it in that case
'If you found this code useful, please don't forget to thank me on my email --> Brix102778@gmail.com
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks