Re: function PlaySound does not work



"Susanne Wenzel" <wirdnichtgelesen@xxxxxxxxxxxxx> wrote in message
news:1xqpw086ku6pa$.dlg@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi to everyone,

I have no idea whether this group is the right one for my problem so I
just
try (and maybe I'm lucky:-)

I'm getting nowhere in trying to play a .wav-file using the function
Playsound. There's no sound, no noise to be heard when I use this function
in vb(a), actually excel-vba, same thing happens in delphi. It does not
matter if I step through the code one by one or start it via GUI. If I try
via Single-Step-Mode (I hope I've translated it somewhere near the correct
one) at least he (i.e. my computer) takes a little time until he proceeds
to the next step. As if he was doing something... The return-code I'm
getting is 1, so he thinks he's successful.

Nowhere did I cross out anything in the sound volume. If I start the
.wav-file by doubleclick in the explorer, I can hear the sound loud and
clearly, no problem.

I have no idea where to look to solve this little but nevertheless
annoying
problem. I know from several other users that they had no problems using
my
little function: they could start the .wav-file via vba and heard it.:-)

But I can't.:-(

Does anyone here have an idea or just a link for me?
Any help would be appreciated.

This is the code I used... to no avail:-(

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

Public Sub Klang()
Dim a
a = sndPlaySound32("C:\WINNT\Media\tada.wav", 0)
Debug.Print a
End Sub

Thanks for reading
Greetings from Germany
Susanne

--
Mein System:
Office XP, SP3, aktueller Patchstand
Windows 2000, SP4, aktueller Patchstand

Your code works fine in my system, Windows XP. I changed the file path
because Windows XP uses "C:\Windows" instead of "C:\WINNT". Here is the
revised code:

Public Sub Klang()
Dim a
a = sndPlaySound32("C:\Windows\Media\tada.wav", 0)
Debug.Print a
End Sub

Why not using PlaySound()? Try this example:



Public Const SND_APPLICATION As Long = &H80
Public Const SND_ALIAS As Long = &H10000
Public Const SND_ALIAS_ID As Long = &H110000
Public Const SND_ASYNC As Long = &H1
Public Const SND_FILENAME As Long = &H20000
Public Const SND_LOOP As Long = &H8
Public Const SND_MEMORY As Long = &H4
Public Const SND_NODEFAULT As Long = &H2
Public Const SND_NOSTOP As Long = &H10
Public Const SND_NOWAIT As Long = &H2000
Public Const SND_PURGE As Long = &H40
Public Const SND_RESOURCE As Long = &H40004
Public Const SND_SYNC As Long = &H0
Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" ( _
ByVal lpszName As String, _
ByVal hModule As Long, _
ByVal dwFlags As Long) As Long

Public Sub Klang()
Dim a As Long
a = PlaySound("C:\WINNT\Media\tada.wav", 0, SND_ASYNC)
Debug.Print a
End Sub





.



Relevant Pages

  • Any good Form Resizing code?
    ... Option Compare Database 'Use database order for string comparisons ... Public Const glrcMDIClientClass = "MDICLIENT" ... Dim strName As String ... sglFactorY As Single) ...
    (comp.databases.ms-access)
  • Invalid handle after calling LsaQueryInformationPolicy
    ... Private Declare Function LsaOpenPolicy Lib "advapi32.dll" (_ ... Public Const STATUS_SUCCESS As Long = 0 ... Dim lBufPtr As Long ... Dim lReturn As Long ...
    (microsoft.public.vb.winapi)
  • Re: lines and mouse scroll
    ... If you want to use the mouse wheel in your program try this: ... Public Const MK_CONTROL = &H8 ... Dim LocalPrevWndProc As Long ... Public Sub WheelHook ...
    (microsoft.public.vb.general.discussion)
  • Re: How to search Notes Field
    ... Public Const xlHAlignCenterAcrossSelection = 7 ... ' This function can be used to search for a keyword in the task notes. ... Dim MsgBoxReturn As Integer ... ' opens up excel and exports notes and related info to excel. ...
    (microsoft.public.project)
  • Re: lines and mouse scroll
    ... If you want to use the mouse wheel in your program try this: ... Public Const MK_CONTROL = &H8 ... Dim LocalPrevWndProc As Long ... Public Sub WheelHook ...
    (microsoft.public.vb.general.discussion)