| | |
Playing .Wav/MIDI files in a Visual Basic Program
![]() |
0
#2 Jun 11th, 2003
What did you find? What you found DOES work but only in VB4? Are you looking for something for VB.NET ?
here's a module I used to play sounds. I don't remember how I did it with just the .wav fiile, but I THINK you can just put the name of the file in place of loadresdata. But in this example I have my .wav files saved in my resource file with id's of 101 and 102. If your app is always going to use the same set of sounds, I think this is the easiest way, and quicker. So to play the sound I just call MySounds(101) and it plays that file. Here's the snippet from a module:
Option Explicit
Public Declare Function sndPlaySound Lib _
"winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Const SND_ASYNC = &H1
Public Const SND_MEMORY = &H4
Public Sub MySounds(intSound As Integer)
'101 is drums sound used for startup
'102 is bop sound used for going from form to form
sndPlaySound StrConv(LoadResData(intSound, "custom"), vbUnicode) _
, SND_ASYNC Or SND_MEMORY
DoEvents
End Sub
Option Explicit
Public Declare Function sndPlaySound Lib _
"winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Const SND_ASYNC = &H1
Public Const SND_MEMORY = &H4
Public Sub MySounds(intSound As Integer)
'101 is drums sound used for startup
'102 is bop sound used for going from form to form
sndPlaySound StrConv(LoadResData(intSound, "custom"), vbUnicode) _
, SND_ASYNC Or SND_MEMORY
DoEvents
End Sub
•
•
•
•
Originally Posted by Stooge
bdiamond, any chance you could use sndPlaySound in a code snippet? I'm not sure how to employ it. thanks.
I see this is your first post, So, Welcome To Daniweb, and I hope you enjoy the site. One favor I am going to have to ask you, right off the bat, is not to piggy or resurrect ancient threads. This thread has been dead for a year, and it's best (and proper) to start your own thread if you have a question. Thanx, and I hope to be able to be of assistance to you.
•
•
Join Date: Aug 2008
Posts: 2
Reputation:
Solved Threads: 0
Dear Spartan,
Having the same trouble trying to get vb.net 2005 to run midi files. I was referred to this link http://forums.msdn.microsoft.com/zh-...-b6ffab8596e8/
this forum might help you.
Having the same trouble trying to get vb.net 2005 to run midi files. I was referred to this link http://forums.msdn.microsoft.com/zh-...-b6ffab8596e8/
this forum might help you.
•
•
Join Date: Jun 2009
Posts: 1
Reputation:
Solved Threads: 0
For VB4 ( Visual Basic 4 ) VB4.0 ( Visual Basic 4.0 )
To play a sound the easiest and quickest way:
THIS WORKS!
Shell ("sndrec32" & " /play /close " & Text1.Text)
Replace Text1.Text with whatever your using to play a sound.
This will open sound-recorder of built into windows and play the sound then close the player once it is done.
This works, this is what I use. There may be a switch to make it stay invisible.
To play a sound the easiest and quickest way:
THIS WORKS!
Shell ("sndrec32" & " /play /close " & Text1.Text)
Replace Text1.Text with whatever your using to play a sound.
This will open sound-recorder of built into windows and play the sound then close the player once it is done.
This works, this is what I use. There may be a switch to make it stay invisible.
![]() |
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: IF THEN ELSE Statement
- Next Thread: Connect to database using ODBC and dot net.
| Thread Tools | Search this Thread |
* 6 2007 access activex add age basic birth bmp calculator cd cells.find click client code connection connectionproblemusingvb6usingoledb creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit excel excelmacro file filename form header iamthwee image inboxinvb internetfiledownload listbox listview liveperson login looping microsoft movingranges objectinsert open oracle password program prompt range-objects readfile reading remotesqlserverdatabase report save search sendbyte sites sql sql2008 sqlserver subroutine tags time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web windows







