View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default How to tell when Beep sound is done?


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)


On Sun, 13 Sep 2009 05:17:14 -0700, "JoeU2004"
wrote:

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