Sleeping in VBA (Integer Overflow!!)
Asked Answered
U

1

0

In VBA you can

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

to provide yourself with a sleep routine.

However, the Long that must be passed to the routine appears to overflow for values in excess of 32000 milliseconds.

Is there a way to sleep for longer periods of time without the complexity of stringing together several consecutive calls to the sleep routine?

Unterwalden answered 28/5, 2010 at 16:42 Comment(1)
Does calling Sleep in a loop count as "stringing together several consecutive calls"?Sb
L
2

No, it doesn't overflow, unless your code that calculates required number of milliseconds causes an overflow.

Example:

dim t as long
t = 10000 * 10000 / 10000 'Overflow

Example 2:

dim t as long
t = 10000! * 10000 / 10000 'Ok
Lait answered 28/5, 2010 at 17:21 Comment(1)
You're right. The issue was only that I failed to specify that my argument was a Long with sufficient explicitness.Unterwalden

© 2022 - 2024 — McMap. All rights reserved.