Here is a sub that I use:
' API Declaration
Declare Auto Function sndPlaySound Lib "WINMM.DLL" (ByVal FileName As String, ByVal Options As Int32) As Int32
' For Info
' API Call Flags for sndPlaySound
Const SND_SYNC = &H0 'synchronize playback - 'locks' app until sound finished
Const SND_ASYNC = &H1 ' played async - app continues while sound playing
Const SND_NODEFAULT = &H2 ' No default sound played if file not found
Const SND_LOOP = &H8 ' 'loop the wave
Const SND_NOSTOP = &H10 'don't stop current sound if one playing
Const SND_NOWAIT = &H2000 'Do not wait if the sound driver is busy.
Const SND_ALIAS = &H10000 ' Play a Windows sound (such as SystemStart, Asterisk, etc.).
Public Sub PlayAWave(ByVal Soundfile As String, Optional ByVal MaxLoops As Integer = 1)
' Play a wav file one or more times, as required
Dim i As Integer
For i = 1 To MaxLoops
' Play Async - ie. Don't lock up the application
sndPlaySound(Soundfile, SND_ASYNC And SND_NOSTOP)
Next
End Sub
|