Home |
Search |
Today's Posts |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"Faraz A. Qureshi" wrote:
The mistake was that I had inserted "/" instead of an "OR"! Ironically, I began to suspect as much when I read Chip's posting, and I to think about the potential ambiguity of "3 / 5". I had ass-u-me-d that "no one" would want to beep for 30 to 50 seconds (!). Anyway, in that case, Michelle's first solution might be the best one insofar as it is the most straight-forward. Namely: Application.Wait Now() + TimeSerial(0,0,5) The point is, as Chip stated so "diplomatically": do not use a timing loop, at least not when some better method works. One caveat: VB Now() truncates time to the second, in contrast to Excel Now(), which has a resolution of ten millisecond, as I recall. So the Wait method above might be off by as much as nearly one second. If that concerns you, the Sleep solution that I presented might be preferrable. Or use Chip's SleepEx solution if you like adding complexity that you might not understand ;-). On the other hand, one advantage of the Wait method is that it is portable among platforms (i.e. Mac and Windows). I don't know if the same can be said for any kernel32 lib functions. ----- original message ----- "Faraz A. Qureshi" wrote in message ... I am really sorry Joe! The mistake was that I had inserted "/" instead of an "OR"! -- Best Regards, Faraz "JoeU2004" wrote: "Chip Pearson" wrote: And the code that Michelle posted, to which you are replying, For y = 1 To 50000000 Next y This is probably the absolutely worst way to cause some sort of pause in code execution. My reaction as well. But I figured "you can lead a horse to water, but you cannot make him drink". A vastly better way is to use the SleepEx API: Public Declare Function SleepEx Lib "kernel32" ( _ ByVal dwMilliseconds As Long, _ ByVal bAlertable As Long) As Long Since you are setting bAlertable to zero (uninterruptible), why not use the even simpler Sleep API, as I did? Dim PauseSeconds As Long PauseSeconds = 5 [....] SleepEx dwMilliseconds:=PauseSeconds * 1000&, bAlertable:=0 Since the OP wants a delay 3/5 sec, why are you using 5 seconds in your example? I believe the correct implementation is, minimally: Dim PauseSeconds as Double PauseSeconds = 3 / 5 ..... SleepEx dwMilliseconds:=PauseSeconds * 1000, bAlertable:=0 I believe VB will convert the Double PauseSeconds*1000 to Long by applying "banker's rounding". To ensure "normal" rounding, I would do: SleepEx dwMilliseconds:=PauseSeconds * 1000 + 0.5, bAlertable:=0 Alternatively, you could do: Dim PauseMsec as Long PauseMsec = 600 ..... SleepEx dwMilliseconds:=PauseMsec, bAlertable:=0 ----- original message ----- "Chip Pearson" wrote in message ... However, what's the logic of using BYTE??? A misguided effort to use the smallest possible data type. Memory is so plentiful and cheap that it makes no sense to worry about saving a byte here and there. (And if you were concerned to the point where individual bytes really mattered, VBA is decidedly not the right platform to begin with. Strict ANSI C, not even C++, for super tight memory requirements.) All integral numerics should be Longs, as software is optimized for 32 bits and short ints end up getting converted to longs by the CPU. Floating points should always be Doubles. Forget about Byte, Integer, and Single. On rare occasion you may need an Byte array, but a single Byte variable is of no value. And the code that Michelle posted, to which you are replying, For y = 1 To 50000000 Next y This is probably the absolutely worst way to cause some sort of pause in code execution. A vastly better way is to use the SleepEx API: Public Declare Function SleepEx Lib "kernel32" ( _ ByVal dwMilliseconds As Long, _ ByVal bAlertable As Long) As Long Sub AAA() Dim PauseSeconds As Long PauseSeconds = 5 ' ' your code here ' ' pause execution SleepEx dwMilliseconds:=PauseSeconds * 1000&, bAlertable:=0 ' ' the rest of your code here ' End Sub Cordially, Chip Pearson Microsoft Most Valuable Professional Excel Product Group, 1998 - 2009 Pearson Software Consulting, LLC www.cpearson.com (email on web site) On Sun, 13 Sep 2009 02:25:01 -0700, Faraz A. Qureshi wrote: Thanx Michelle! That was excellent! However, what's the logic of using BYTE??? |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Beep | Excel Programming | |||
No Beep | Excel Programming | |||
Is BEEP all there is?? | Excel Programming | |||
I want to *beep* *beep*!!!! | Excel Programming | |||
I want to *beep* *beep*!!!! | Excel Programming |