LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,059
Default Beep & Time

"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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beep Antonio Excel Programming 7 February 8th 07 03:05 AM
No Beep Certior Excel Programming 2 October 24th 05 05:01 PM
Is BEEP all there is?? Gary's Student Excel Programming 5 May 4th 05 07:42 PM
I want to *beep* *beep*!!!! Jake Marx[_3_] Excel Programming 1 February 22nd 04 01:00 PM
I want to *beep* *beep*!!!! KJTFS[_105_] Excel Programming 0 February 20th 04 02:59 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"