Advertise Information
Trapped in somebody else's frames?  BreakOut!!!

Play a WAV file in VB

This example shows how to play a WAV file in VB. It requires one declaration (API) and one SUB. The declaration looks like this:

  '   Declare Function sndPlaySound Lib "MMSYSTEM" (ByVal lpWavName$, ByVal Flags%) As Integer

Next, create a SUB to actually handle the playing of the WAV file. We'll call it PlaySound. It requires one argument to be passed to it. The argument filename is the name of the WAV file to play.

Sub PlaySound (FileName As String)
  Dim x%
  x% = sndPlaySound(FileName, 1)
End Sub

Finally, place a command button or some other control on the form and place the following code in it's click event procedure. We'll use TADA.WAV for the sound to play, but it could just as easily be any WAV file you like.

Command1_Click
    PlaySound ("tada.wav")
End Sub

Finally, just run the program and click the button!