ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Fraction of seconds (https://www.excelbanter.com/excel-programming/367329-fraction-seconds.html)

ArthurJ

Fraction of seconds
 
I have set up a timer as follows:

Dim alertTime
alertTime = Now + TimeValue("00:00:01")
Application.OnTime alertTime, "procedure"

This does what I want, except I require time intervals less than one second.

Is this possible?

Art



RB Smissaert

Fraction of seconds
 
Simplest for if you just want a little wait is use the Sleep API.
Put this at the top of your normal module:

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

And use it like this:

Sleep 300 'wait 300 milli-seconds

procedure


RBS



"ArthurJ" wrote in message
...
I have set up a timer as follows:

Dim alertTime
alertTime = Now + TimeValue("00:00:01")
Application.OnTime alertTime, "procedure"

This does what I want, except I require time intervals less than one
second.

Is this possible?

Art




Leith Ross[_658_]

Fraction of seconds
 

Hello Art,

You have 2 choices for more precision. The VBA Timer will provide yo
with accuracy to 1/100 of a second. The API timer will provide accurac
to 1/1,000 of a second.

The VBA Timer is easy yo use but has to be used in a loop. The AP
Timer is more a little more complex but can runs unattended in th
background. I am going to skip posting the API Timer code due to it
length. If you decide you need the API Timer, let me know in your nex
post and I will post the code separately.

VBA Timer example...

Code
-------------------

Sub TimeLoop()

Delay = 0.02
StartTime = Timer

Do While Timer < StartTime + Delay
DoEvents
'Your code goes in here
Loop

End Sub

-------------------


Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=56184


ArthurJ

Thanks RBS & Leith (eom)
 



All times are GMT +1. The time now is 02:42 AM.

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