Solved

Playing WAV files without OLE

Posted on 1998-06-16
1
142 Views
Last Modified: 2012-05-04
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
Comment
Question by:cobrapc
1 Comment
 
LVL 9

Accepted Solution

by:
Dalin earned 50 total points
ID: 1463461
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now