Playing a WAV file
By: Microsoft Corp. Date: 01/05/1998

The simpliest way of playing a wave (.WAV) file is to use a Windows API call.
First you must declare the sndPlaySound API. To do this, use this line in a public module:

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

Second, you have to declare the Windows API constants:

Public Const SND_ASYNC = &H1
Public Const SND_LOOP = &H8
Public Const SND_SYNC = &H0

Note that if you want to declare the function or the constants as private (i.e. in a form module), their declare statements will begin with Private instead of Public.
Third, insert the API call where you want the sound to be played:

SoundName$ = filename
wFlags% = flags
X = sndPlaySound(SoundName$, wFlags%)

For filename specify the name and path of the wave file (i.e. "C:\Windows\Media\Ding.Wav"). For flags type the name of the constants you want with an Or keyword between them (i.e. SND_ASYNC Or SND_LOOP). SND_ASYNC plays the sound asyncronously: after the sound starts, the command is passed to the next statement. SND_SYNC waits the end of the sound before proceeding with the program execution. SND_LOOP loops the sound.

Click Here!

Visual Basic Programming Zone is a website by Lorenzo Dalla Vecchia.
Webmaster's e-mail:
Hosted by InWind: