Try this example:
Option Explicit
Private Declare Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName _
As String, ByVal uFlags As Long) As Long
Const SND_ALIAS = &H10000
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
Const SND_LOOP = &H8
Const SND_MEMORY = &H4
Const SND_NODEFAULT = &H2
Const SND_NOSTOP = &H10
Const SND_SYNC = &H0
'Dim SoundFile As String
Dim SoundInMemory(1 To 8) As String
Private Function LoadSound(FileName As String) As String
On Error GoTo Error_Handler
Dim FreeFileNumber As Integer
Dim SoundBuffer As String
FreeFileNumber = FreeFile
SoundBuffer = Space$(FileLen(FileName))
Open FileName For Binary As #FreeFileNumber
Get #FreeFileNumber, , SoundBuffer
Close FreeFileNumber
LoadSound = Trim$(SoundBuffer)
Error_Handler:
Select Case Err
Case 0
Case Else
Err.Clear
LoadSound = ""
End Select
End Function
Private Sub Form_Load()
SoundInMemory(1) = LoadSound("c:\windows\media\notify.wav")
SoundInMemory(2) = LoadSound("c:\windows\media\chord.wav")
SoundInMemory(3) = LoadSound("c:\windows\media\chimes.wav")
End Sub
Private Sub Command1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
' Play a sound file (held in memory)
sndPlaySound SoundInMemory(1), SND_ASYNC Or SND_MEMORY
End Sub
Private Sub Command2_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
' Play a sound file (held in memory)
sndPlaySound SoundInMemory(2), SND_ASYNC Or SND_MEMORY
End Sub
Private Sub Command3_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
' Play a sound file (held in memory)
sndPlaySound SoundInMemory(3), SND_ASYNC Or SND_MEMORY
End Sub
Quote:
> Hi,
> I have made this program to exercise maths. Now I want to add sound to
> it. (it's my first real program...) The sound says "good" or "bad"
> from a file. Everything works fine, except when it goes a little too
> fast. Now I was wondering : is there a way to load all sounds into
> memory and play them from there instead of getting them from the
> harddisk every time ?
> Thanks in advance !
> Bart
> Sorry if I've missed FAQ, but I'm new to this group and need the
> answer rather quickly. Ow, and English isn't my first language ;-)