473,569 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a way to randomize or loop through a set of wav sounds--for fun?

Hi there,

Here's the situation--there is a text field in a form in which students
will key in data. On the keypress event, I'd like for different sounds
to be played for each character typed, either randomly or in a loop (I
have a number of small, cool, computer-like sounds). I can get one
sound to play for the keypress event, but don't know how to play
multiple sounds.

Here's the codes for playing one sound...
_______________ _______________

Private Sub Text0_KeyPress( KeyAscii As Integer)

PlaySound ("C:\WINDOWS\Me dia\Sound, bleep.wav")
_______________ _______________

In a module mdlPlaySound

' http://odyssey.apana.org.au/~abrowne/func-04.html

Function PlaySound(sWavF ile As String)

If apisndPlaySound (sWavFile, 1) = 0 Then
MsgBox "The Sound Did Not Play!"
End If
End Function

Many thanks in advance,
Arnold

Feb 5 '06 #1
4 2216

"Arnold" <ee*******@kc.r r.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
Hi there,

Here's the situation--there is a text field in a form in which students
will key in data. On the keypress event, I'd like for different sounds
to be played for each character typed, either randomly or in a loop (I
have a number of small, cool, computer-like sounds). I can get one
sound to play for the keypress event, but don't know how to play
multiple sounds.

Here's the codes for playing one sound...
_______________ _______________

Private Sub Text0_KeyPress( KeyAscii As Integer)

PlaySound ("C:\WINDOWS\Me dia\Sound, bleep.wav")
_______________ _______________

In a module mdlPlaySound

' http://odyssey.apana.org.au/~abrowne/func-04.html

Function PlaySound(sWavF ile As String)

If apisndPlaySound (sWavFile, 1) = 0 Then
MsgBox "The Sound Did Not Play!"
End If
End Function

Many thanks in advance,
Arnold



Doing this might be more involved than you thought, especially if you want
to randomize these files. You would also have to specify more exactly the
random selections that are made. In this example, I look at all the wav
files in a folder, put them into a randomized order and then get keep
getting the next one until I have played each file once. Then I go back to
the start of the list (without re-randomizing) and repeat the procedure.

All of this code should be put in your form's code module.
Option Compare Database
Option Explicit

Private Const SOUNDS_FOLDER As String = "C:\Program Files\Windows
NT\Pinball\"
Dim m_astrFiles() As String
Dim m_lngIndex As Long

Private Function PlayNextFile() As Boolean

On Error GoTo Err_Handler

Dim strPath As String
Dim lngReturn As Long

If m_lngIndex > UBound(m_astrFi les()) Then
m_lngIndex = 0
End If

strPath = SOUNDS_FOLDER & m_astrFiles(m_l ngIndex)

m_lngIndex = m_lngIndex + 1

If PlaySound(strPa th) > 0 Then
PlayNextFile = True
End If

Exit_Handler:
Exit Function

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Function

Private Function CreateFileArray () As Boolean

On Error GoTo Err_Handler

Dim strFileList As String
Dim astrTemp() As String
Dim lngFileCount As Long
Dim lngCount As Long
Dim strValue As String
Dim strFile As String
Dim lngIndex As Long

astrTemp = Split(strFileLi st, "|")

lngFileCount = UBound(astrTemp ()) + 1

strFile = Dir(SOUNDS_FOLD ER & "*.wav")

Do Until Len(strFile) = 0
lngFileCount = lngFileCount + 1
strFileList = "|" & strFile & strFileList
strFile = Dir()
Loop

If Len(strFileList ) > 1 Then
strFileList = Mid$(strFileLis t, 2)
End If

astrTemp() = Split(strFileLi st, "|")

ReDim m_astrFiles(0 To lngFileCount - 1)

Randomize

For lngCount = 0 To lngFileCount - 1
strValue = Format((1000000 * Rnd), "000000") & "_" & _
Format(lngCount , "000000")
m_astrFiles(lng Count) = strValue
Next lngCount

Call QuickSortArray( m_astrFiles())

For lngCount = 0 To lngFileCount - 1
strValue = m_astrFiles(lng Count)
strValue = Mid$(strValue, 8)
lngIndex = CLng(strValue)
m_astrFiles(lng Count) = astrTemp(lngInd ex)
Next lngCount

CreateFileArray = True

Exit_Handler:
Exit Function

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Function

Private Function QuickSortArray( VarArray As Variant, _
Optional lngFirst As Long = -1, _
Optional lngLast As Long = -1) As Variant

Dim lngLow As Long
Dim lngHigh As Long
Dim lngMiddle As Long
Dim varTempVal As Variant
Dim varTestVal As Variant

If lngFirst = -1 Then lngFirst = LBound(VarArray )
If lngLast = -1 Then lngLast = UBound(VarArray )

If lngFirst < lngLast Then
lngMiddle = (lngFirst + lngLast) / 2
varTestVal = VarArray(lngMid dle)
lngLow = lngFirst
lngHigh = lngLast
Do
Do While VarArray(lngLow ) < varTestVal
lngLow = lngLow + 1
Loop
Do While VarArray(lngHig h) > varTestVal
lngHigh = lngHigh - 1
Loop
If (lngLow <= lngHigh) Then
varTempVal = VarArray(lngLow )
VarArray(lngLow ) = VarArray(lngHig h)
VarArray(lngHig h) = varTempVal
lngLow = lngLow + 1
lngHigh = lngHigh - 1
End If
Loop While (lngLow <= lngHigh)
If lngFirst < lngHigh Then QuickSortArray VarArray, lngFirst,
lngHigh
If lngLow < lngLast Then QuickSortArray VarArray, lngLow, lngLast
End If

End Function

Private Sub Form_Open(Cance l As Integer)
If Not CreateFileArray () Then
MsgBox "Error creating file array", vbExclamation
Cancel = True
End If
End Sub

Private Sub Text0_KeyPress( KeyAscii As Integer)
If Not PlayNextFile() Then
Exit Sub
End If
End Sub

Feb 6 '06 #2
I have hundreds of wav and mp3 files that I use in my database.
Some of the audio responses are informative ("The start date must be
earlier than the end date"); some are for entertainment ("Hotel
California"); and some are just plain foolishness. Most of the
responses are hard wired to a particular function. The music is
selectable off of a list. The foolishness just has to be endured.
I also have a few dozen pictures: Some for the employee file and some
I use RANDOMILY with my built in Screen Saver. I have a table with all
the picture names and a field that holds a number from 1 to N. Then I
generate a random number once per minute to pull the next picture from
the table. CInt((100 * Rnd) + 1) should give you a number between 1
and 100. Remember to use Randomize.
None of the sounds or pictures are in the database but are simply
referred to with a folder path and name when needed. Once you have
that Windows Media Player in place, you can also use it to play videos,
which I use for instructional purposes (Like how I do I braze a joint)
Good luck,
Hank Reed

Feb 6 '06 #3
"Hank" <ha********@aol .com> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.com...
I have hundreds of wav and mp3 files that I use in my database.
Some of the audio responses are informative ("The start date must be
earlier than the end date"); some are for entertainment ("Hotel
California"); and some are just plain foolishness. Most of the
responses are hard wired to a particular function. The music is
selectable off of a list. The foolishness just has to be endured.
I also have a few dozen pictures: Some for the employee file and some
I use RANDOMILY with my built in Screen Saver. I have a table with all
the picture names and a field that holds a number from 1 to N. Then I
generate a random number once per minute to pull the next picture from
the table. CInt((100 * Rnd) + 1) should give you a number between 1
and 100. Remember to use Randomize.
None of the sounds or pictures are in the database but are simply
referred to with a folder path and name when needed. Once you have
that Windows Media Player in place, you can also use it to play videos,
which I use for instructional purposes (Like how I do I braze a joint)
Good luck,
Hank Reed

Of course if you had all the paths stored in a table, it would be much
easier. However it does have the down side that someone has got to put them
there in the first place and also have to keep the list synchronized with
what's stored on the machine. If files are deleted from the os, then your
table will not be updated. The solution I outlined, looks them up 'live' so
to speak (but currently only looks at in one folder).


Feb 6 '06 #4
Thanks Anthony and Hank,

It's been a few days since I logged on and to my surprise, there is an
enormous chunk of code here--thanks very much for responding. I
normally store my sounds in the C:\Windows\Medi a folder. I'll try to
incorporate the code in a few days.

I've found that having something as easy as simple sounds and pictures
in a database sparks interest in the special kids I teach. I just
learned how to use the Gif89.dll to insert animations in Access and am
exited about that as well.

Take care,
Arnold

Feb 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
4152
by: Jeff Thies | last post by:
I'd like to randomly sort an array. A good method?
3
14617
by: Gaffer | last post by:
Hello Is there a way in which I can make certain parts of Html on my website random so that each viewer will see different material if they refresh the page or come back onto the website later? I am currently using the "<!--#include virtual="cgi-bin/menu1.txt" -->" command to display my menus on every page of my site, so that the same...
6
3859
by: ashu | last post by:
can any one tell me that is there any way to get a randomize (genuine) character like integer. for integer, we use random function. & for character, we use ????
1
3418
by: Ellen Manning | last post by:
I've got an A2K database with a report that generates any number of random medical record numbers. The user inputs how many numbers they want and report uses the Randomizer function found on "The Access Web" site to generate these numbers. Out of 38000 records, there are 900 unique medical record numbers. I run the randomizer function on a...
2
2471
by: Rich | last post by:
Here is what I am trying for randomizing 2 numbers in the same subroutine so that they are not equal to each other: Dim j As Integer, k As Integer j = New System.Random().Next(0, 10) k = New System.Random().Next(0, 10) But j and k are always equal to each other. So I through in Randomize( ) but that did not help. Is it possible to...
1
3750
by: Badass Scotsman | last post by:
Hello, This code is supposed to generate a random string each run, however I have had it live on a few sites, and it seems to create repeat strings all over the place. ------------------------------------------------------------- <% FUNCTION GetRandomCode(randomcode,codelength,numberofcombinations) codecharacters = 35
1
1555
by: Samuel Shulman | last post by:
Any function to randomize strings? thank you, Samuel
6
2387
by: mrtaka79 | last post by:
Okay, first of all, I'm a complete noob, so go easy on me. I have this code that works perfectly for me. The only thing I want to add is to randomize the pictures/links that show up. Can anyone just tell me where to add additional code to the following? BTW this is the only code I could find that works in my Beta Blogger sidebar. <a...
5
2880
by: gggram2000 | last post by:
Hi, I'ved spent two full days trying to find a solution, I can randomize numbers between two ranges and it works fine, But my problem is when i want to randomize five numbers that I got. eg. I randomize 1-100 and I get 50. I randomize 1-900 on another input field and I get 578. I randomize 2-56 and get 31. " " and get 43. " " and get...
0
7697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.