Solved

Playing WAV files without OLE

Posted on 1998-06-16
1
146 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

840 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