VB: PLAY a Wave File function (got it), how can i remove the quotes, in top eg

NOTE:  Answer for play a wave function,  is at the bottom of this "Top" post.  thanks.

UPDATE:  i got the main part working per below.  (guesse i only half made it since from like 5 different parts :) and not see a play wave function anwhere else..  is there a way to shorten the request line,  to remove the quotes around the wave file name ??  thanks.   for eg:

    playWAVE (tada)   'no, prefer this format,  see function under line:  ANSWER:  AAAHHH   below
    'playWAVE ("tada")   'yes

==========

hi,  i put together a function from parts, to try to make a wave file play as part of a shorter command.

it does not quite work yet.  guessing some small syntax problems.  thanks in advance.

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
'insert at top of your code module (before any procedure declarations but after Option statements)
'verify path & file name exist.  if file not found windows will play default sound: beep 
  Const SND_SYNC = &H0
  Const SND_ASYNC = &H1
  Const SND_FILENAME = &H20000

Sub xPlayWAV()    'YES  part of:  Private Declare Function PlaySound   (this item works)
    Dim wavFILE As String
    wavFILE = "C:\Windows\Media\tada.wav"
    Call PlaySound(wavFILE, 0&, SND_ASYNC Or SND_FILENAME)
End Sub

Sub waveTEST()    'CANNOT GET THIS TO WORK,  using function below
    playWAVE (tada)   'no, prefer end example works like this format
    'playWAVE ("tada")   'yes
End Sub
  

Function playWAVE(strFileName As String)    'not working yet    obj err try:  set item =
    Dim wavFILE As String
    On Error Resume Next
    Set wavFILE = ("C:\windows\media\" & strFileName & ".wav")    'err:  wavFILE =  obj required
    On Error GoTo 0
    
    Call PlaySound(wavFILE, 0&, SND_ASYNC Or SND_FILENAME)
    
    'Call PlaySound(playWAVE, 0&, SND_ASYNC Or SND_FILENAME)
End Function

==========    ANSWER:  AAAHHH   not sure how got all working:

'GIVEN:

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
'insert at top of your code module (before any procedure declarations but after Option statements)
'verify path & file name exist.  if file not found windows will play default sound: beep 
  Const SND_SYNC = &H0
  Const SND_ASYNC = &H1
  Const SND_FILENAME = &H20000

'MAIN:

Sub waveTEST()    'YES  WORKS
    playWAVE ("tada")   'yes

    'playWAVE (tada)   'no, prefer end example works like this format
End Sub
 

'NOTE:  I removed "set" from:   set item  =    and then using the current  command line.

Function playWAVE(strFileName As String)    'YES!!  WORKS.
    Dim wavFILE As String
    On Error Resume Next
    wavFILE = ("C:\windows\media\" & strFileName & ".wav")    'err:  wavFILE =  obj required,  removed:  "Set" item =
    On Error GoTo 0
    
    Call PlaySound(wavFILE, 0&, SND_ASYNC Or SND_FILENAME)    'YES
End Function

Answer
Answer

Hi Dave,


This kind of issue is more complex than what is normally posted here in the Community. We suggest you to post your query in our MSDN Forum for further assistance. 
 
Thanks.       

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated April 13, 2025 Views 168 Applies to: