# Visual Basic help

**URL:** <https://boards.straightdope.com/t/visual-basic-help/26760>\
**Category:** Factual Questions\
**Created:** [July 25, 2000, 11:36am UTC](https://boards.straightdope.com/t/visual-basic-help/26760 "2000-07-25T11:36:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MadHatter](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@MadHatter](https://boards.straightdope.com/u/MadHatter)\
**Post date:** [July 25, 2000, 11:36am UTC](https://boards.straightdope.com/t/visual-basic-help/26760/1 "2000-07-25T11:36:22Z")

</div>

Ok, I have button called cmdplay and when I press that button I want a wav sound to play. How do I do it?

---

<div class="post-metadata">

**Author:** ![Bryan](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@Bryan](https://boards.straightdope.com/u/Bryan)\
**Post date:** [July 25, 2000, 2:18pm UTC](https://boards.straightdope.com/t/visual-basic-help/26760/2 "2000-07-25T14:18:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CurtC](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@CurtC](https://boards.straightdope.com/u/CurtC)\
**Post date:** [July 25, 2000, 3:14pm UTC](https://boards.straightdope.com/t/visual-basic-help/26760/3 "2000-07-25T15:14:27Z")

</div>

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)
