Teen Programmers Unite  
 

 

Return to forum top

How to play sounds (.wav. And using Visual Basic)

Posted by AndiProg [send private reply] at September 15, 2002, 01:59:07 PM

This is simple code for playing sounds (.wav) using visual Basic. first create a module and paste or type the following code:


Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Enum SND_Settings
SND_SYNC = &H0
SND_ASYNC = &H1
SND_NODEFAULT = &H2
SND_MEMORY = &H4
SND_LOOP = &H8
SND_NOSTOP = &H10
SW_SHOW = 5
End Enum

Public Sub Play(fname As String, Optional Settings As SND_Settings = SND_ASYNC)
Dim retval As Long
retval = sndPlaySound(fname, Settings)
End Sub

Then, to play the sound you want, use the play command on a control (Command Buttons are exellent.):

Play "c:\song.wav"

NOTE: The filename "song" can be changed to any .wav file you saved on your disk

Posted by jay_dee [send private reply] at September 15, 2002, 04:08:31 PM

ummmm...thanks??

Posted by diegoeskryptic [send private reply] at September 15, 2002, 04:20:06 PM

read the FAQ's..... and read the part on the front page for New users.... Welcome to TPU>....

Posted by CViper [send private reply] at September 16, 2002, 08:52:12 AM

and why should one not simply type sndPlaySound( "name", 1 ); ?

Posted by DragonWolf [send private reply] at September 16, 2002, 10:13:13 AM

isn't there a PlaySound in some other library which is the same, but includes a sound application handle?

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.