Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Attaching music or sound bite to a command button!!!

Status
Not open for further replies.

Killfrog

MIS
Nov 11, 2003
1
0
0
GB
I have never needed to do this before!!!

Is there any way I can simply add a sound bite to command button. Therefore when you press the command button it makes the required noise or sound.

Would be greatful!!! thanks
 
Hi, check out the following thread, I think it has what you need.

thread705-30997

There are two ways to write error-free programs; only the third one works.
 
BTW

If you have the Microsoft Multimedia control you can use this as well.

If you drop this control on your form (in this case call it MMCtrl)

In the form load you can set it up like this...
(Set the FilePath to your own Wav file)

Private Sub Form_Load()
With MMCtrl
.Visible = False
.Notify = False
.Wait = True
.Shareable = False
.DeviceType = "WaveAudio"
.FileName = "C:\ms office 97\sounds\LASER.WAV"
.Command = "Open"
End With


In the form unload close it...

Private Sub Form_Unload(Cancel As Integer)
MMCtrl.Command = "close"
End Sub

to play the sound just do this...

MMCtrl.Command = "play"


End Sub

There are two ways to write error-free programs; only the third one works.
 
How do you get the Microsoft Media Cntrol?
Would it be in the toolbox under additional tools in Access?
 
Hi SheepDog, if you've got it, that's where it'll be. Trouble is, I've got Access, Visual Basic 6, and Delphi 7 on my machine, so I don't know what controls come with what, I think it comes with Visual Basic 6.

However, you may be able to download it from somewhere.



There are two ways to write error-free programs; only the third one works.
 
What folder should I put the active x control once I download it?
 
If you put it in the windows system32 folder. You then need to register it using regsvr32. You can do this by going...

Start
Run


then type in

regsvr32 c:\winnt\system32\mci32.ocx

(or your path if different)

You should get confirmation that it's been registered.




There are two ways to write error-free programs; only the third one works.
 
I did what you suggested above and it is all set to work. My only problem is that when I went to the form and went into the toolbox to select it, I get an error message stating that I need to obtain the license in order to use it.
 
Taking this question 1 step further I would need to do the same except i would like to add several buttons to a form and attach a clip to each one but i want the f1-F12 keys to activate the buttons
miletracker
ps sorry for interupting
 
SheepDog,

Applogies, it would appear that you need to have one of the packages installed that this component ships with (includes VB6 C++ not sure if there are any others). Been having a look around and can't find a way around this.

So it would appear that this is only a solution if you have this control already.


miletracker,

Example of code to run when function keys are pressed (so put your choice of sound playing code in each select...)

'In order for this to work you must set
'KeyPreview = Yes on form
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)


'Detect Function Key Pressed and

Select Case KeyCode
Case Is = vbKeyF1
'do f1 stuff here
Case Is = vbKeyF2
'do f2 stuff here
Case Is = vbKeyF3
'do f3 stuff here
End Select

'Cancel default key behaviour
KeyCode = 0

End Sub


There are two ways to write error-free programs; only the third one works.
 
A better solution for everyone !!

Once you've declared the function only one line of code anywhere to play sounds.[smile]

(only drawback is that it'll only play wav files [sad] )

Put the following code in a module...


Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Public Sub gPlaySound(ByVal vstrFileName As String, ByVal vbooWait As Boolean)
Dim lng As Long
Dim intFlag As Integer

If vbooWait Then
intFlag = 0
Else
intFlag = 1
End If

lng = sndPlaySound(vstrFileName, intFlag)

End Sub



You can call this from anywhere with...

gPlaySound &quot;<filepath>&quot;, True/False

Setting the second parameter to True will ensure that the sound will be completely played before any additional sounds that are sent.

Setting it to False will mean that any new sound sent will start immediately (cutting out any already playing).

eg.

gPlaySound &quot;C:\SOUNDS\EXPLODE.WAV&quot;, True



There are two ways to write error-free programs; only the third one works.
 
when i use the suggested code i get an invalid outside Procedure error. i am running XP. any suggestions?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top