Ok, I have button called cmdplay and when I press that button I want a wav sound to play. How do I do it?
Well, you haven’t said what you intend to use to play the .wav, but here’s what I’d do.
Included with the mass of controls you have with VB is the Microsoft MultiMedia Control (MCI32.ocx). If you add this to your form, setting its Visible property to False, you can get simple sound files to play without having to use the control buttons.
For example:
Private Sub cmdPlay_Click()
MMControl1.FileName = “c:\windows
ewmail.wav”
MMControl1.Command = “Sound”
End Sub
You can use this for more complex mutimedia than playing a .wav - have a look through the documentation for details.
Hope this helps,
Bryan.
There’s also a fairly easy way, using the Windows API, that doesn’t require an OCX control. Avoiding OCX controls where feasable makes distribution of your app simpler. Here’s how:
Declare Function PlaySound& Lib “winmm.dll” Alias “PlaySoundA” (ByVal lpszName$, ByVal hModule&, ByVal dwFlags&)
Declare Function waveOutGetNumDevs& Lib “winmm.dll” ()
Public Const SND_FILENAME = &H20000 ’ name is a file name
Public Const SND_SYNC = &H0
Public Const SND_ASYNC = &H1
Public Const SND_NODEFAULT = &H2
Public Const SND_PURGE = &H40
'Public Const SND_LOOP = &H8
Public Const SND_NOSTOP = &H10
Public Const SND_HasFinished = &H10
Public Const SND_NOWAIT = &H2000 ’ don’t wait if the driver is busy
dim wavfile$
wavfile=“mysound.wav”
i = PlaySound(wavfile, 0&, SND_SYNC Or SND_NODEFAULT Or SND_NOWAIT Or SND_FILENAME)