How to tell when Beep sound is done?

J

JoeU2004

On my computer (Intel-compatible with Win XP and VB 6.3, which I access
through Excel 2003), the Beep statement initiates the sound, then it returns
control before the sound is completed.

Is there any way in VB (probably using kernel APIs) to determine when the
sound is completed?

For example, if the Default Beep is set to Windows XP Startup.wav, the sound
takes about 2.75 sec on my computer.

Consequently, the following loop results in interrupting and restarting the
sound instead of playing the sound repeatedly after a delay of 500 msec
after the sound completes.

Public Declare Sub Sleep Lib "kernel32" (ByVal msec As Long)

Sub doit()
Dim i as Long
Beep
For i = 2 to 5
' want to wait for sound to complete here
' before sleeping
Sleep 500
Beep
Next i
End Sub
 
C

Chip Pearson

Try code like the following:

Public Declare Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" ( _
ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long

Sub AAA()
sndPlaySound "Default Beep", 0&
End Sub

Change "Default Beep" to the name that appears for the desired sound
in the Sounds Control Panel applet. sndPlaySound is synchronous, so it
will wait until the sound is done before moving on. Change the 0 to a
1 if for some reason you want async sound.

This works for me in Vista, but I don't have my XP laptop handy to
test with. The code should work the same way in XP as in Vista.


Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
J

JoeU2004

Chip Pearson said:
sndPlaySound "Default Beep", 0&
[....]
This works for me in Vista, but I don't have
my XP laptop handy to test with.

Yup, works fine on XP as well. Thanks.

And now I can say that the Windows XP Startup.wav sound takes about 4.85 sec
(on my computer), not 2.75 sec as I write before.

The latter was measured by stopwatch. When I crank up the speaker volume, I
now do hear sound for nearly 4 sec. I don't doubt that it trails off for
nearly another sec. My hearing isn't what it used to be now that I wear
bifocals ;-).

(Family in-joke.)


----- original message -----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top