Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 151
  • Last Modified:

Playing WAV files without OLE

I can play WAV files by puting an object on the form and then linking to the WAV file. It can then be played on an event (double click). But I want to play some WAV files on Errors and on opening a form. How can I do this
0
cobrapc
Asked:
cobrapc
1 Solution
 
DalinCommented:
cobrapc,
Here are the code for play wav file, any questions, let me know.
Regards
Dalin

 Create a '.BAS' module. Go ahead and name this module 'modPlayWave'.

 Now declare the API functions needed in order to play .WAV files.
 In the General Declarations area of the new module,  enter:

     #If Win32 Then
          Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" _
          (ByVal lpSound As String, ByVal flag As Long) As Long
     #ElseIf Win16 Then
          Declare Function sndPlaySound Lib "MMSYSTEM" _
          (ByVal lpszSoundName As String, ByVal uFlags As Integer) As Integer
     #End If

 

   Now create a procedure and call it PlayWave. This procedure will accept one parameter
   and that will be the filename of the wave file to be played. Let's call this parameter sFileName.

     
     Sub PlayWave(sFileName As String)

         On Error GoTo Play_Err
         
         Dim iReturn As Integer
         
         'Make sure something was passed to the Play Function
         If sFileName > "" Then
             'Make sure a WAV filename was passed
             If UCase$(Right$(sFileName, 3)) = "WAV" Then
                 'Make sure the file exists
                 If Dir(sFileName) > "" Then
                     iReturn = sndPlaySound(sFileName, 0)
                 End If
             End If
         End If
         
         'Wav file play successful
         Exit Sub

     Play_Err:
         'If there was an error then exit without playing
         Exit Sub

     End Sub

 

Now, in where you want to play the WAV,  add the code:
 
        PlayWave "YourWavFileWithPath"
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now