Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using sounds with command buttons (VB.Net)

Posted on 2003-03-18
3
Medium Priority
?
209 Views
Last Modified: 2013-12-26
Greetings, I'm trying to have some buttons on a VB.Net form that have different sounds when pressed.

I've had a little look around and can't seem to find anything.

Any help would be greatly appreciated.
0
Comment
Question by:MikeGW
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
JoaTex earned 200 total points
ID: 8187212
Hi

In your project basic, open a form and put:
3 CommandButtons.

Add a Class Module and put this Class Code:

Class Code:

Option Explicit

'Nome: MMedia.Cls
'Classe Multimidia que executa Ficheiros de Som e de Video

Private sAlias As String   'Armazena nome Ficheiro
Private sFileName As String      'Nome Ficheiro
Private nLength As Single     'Tamanho Ficheiro
Private nPosition As Single      'Posigco Corrente Execugco
Private nStatus As String     'Armazena Estado Actual
Private bWait As Boolean      'Espera Fim do Processo


Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Public Sub mmOpen(ByVal sTheFile As String)
   Dim nReturn As Long        'Valor Devolvido pela mciSendString
   Dim sType As String        'Tipo Ficheiro Multimidia
   If sAlias <> "" Then        'Abre Ficheiro Especificado e fecha os Outros
      mmClose
   End If
   Select Case UCase$(Right$(sTheFile, 3))   'determina Tipo de Ficheiro
      Case "WAV"
         sType = "Waveaudio"
      Case "AVI"
         sType = "AviVideo"
      Case "MID"
         sType = "Sequencer"
      Case Else            'Extensco desconhecida
         Exit Sub
   End Select
   sAlias = Right$(sTheFile, 3) & Minute(Now)   'Hora de Abertura
   nReturn = mciSendString("Open " & sTheFile & " ALIAS " & sAlias & " TYPE " & sType & " Wait", "", 0, 0)
End Sub

Public Sub mmClose()
   Dim nReturn As Long
   If sAlias = "" Then Exit Sub
   nReturn = mciSendString("Close " & sAlias, "", 0, 0)
   sAlias = ""
   sFileName = ""
End Sub
Public Sub mmpause()
   Dim nReturn As Long
   If sAlias = "" Then Exit Sub
   nReturn = mciSendString("Pause " & sAlias, "", 0, 0)
End Sub
Public Sub mmPlay()
   Dim nReturn As Long
   If sAlias = "" Then Exit Sub
   If bWait Then
      nReturn = mciSendString("Play " & sAlias & " Wait", "", 0, 0)
   Else
      nReturn = mciSendString("Play " & sAlias, "", 0, 0)
   End If
End Sub
Public Sub mmStop()
   Dim nReturn As Long
   If sAlias = "" Then Exit Sub
      nReturn = mciSendString("Stop " & sAlias, "", 0, 0)
End Sub
Public Sub mmSeek(ByVal nPosition As Single)
   Dim nReturn As Long
   nReturn = mciSendString("Seek " & sAlias & " to" & nPosition, "", 0, 0)
End Sub
Property Get FileName() As String
   FileName = sFileName
End Property
Property Let FileName(ByVal sTheFile As String)
   mmOpen sTheFile
End Property
Property Get Wait() As Boolean
   Wait = bWait
End Property
Property Get Length() As Single
   Dim nReturn As Long, nLength As Integer
   Dim sLength As String * 255         'String Suporte Tamanho Devolvido
   If sAlias = "" Then
      Length = 0
      Exit Property
   End If
   nReturn = mciSendString("Status " & sAlias & " length", sLength, 255, 0)
   nLength = InStr(sLength, Chr$(0))
   Length = Val(Left$(sLength, nLength - 1))
End Property
Property Let position(ByVal nPosition As Single)
   mmSeek nPosition
End Property
Property Get position() As Single
   Dim nReturn As Integer, nLength As Integer
   Dim sPosition As String * 255
   If sAlias = "" Then Exit Property
   nReturn = mciSendString("Status " & sAlias & " position", sPosition, 255, 0)
   nLength = InStr(sPosition, Chr$(0))
   position = Val(Left$(sPosition, nLength - 1))
End Property
Property Get Status() As String
   Dim nReturn As Integer, nLength As Integer
   Dim sStatus As String * 255
   If sAlias = "" Then Exit Sub
   nReturn = mciSendString("Status " & sAlias & " mode", sStatus, 255, 0)
   nLength = InStr(sStatus, Chr$(0))
   Status = Left$(sStatus, nLength - 1)
End Property

In your form put this Code:

Form Code:
Option Explicit

Dim MultiMedia As New mmedia
Dim Res1
Dim Res2
Dim Res3

Private Sub Command1_Click()
   MultiMedia.mmOpen Res1
   MultiMedia.mmPlay
End Sub

Private Sub Command2_Click()
   MultiMedia.mmOpen Res2
   MultiMedia.mmPlay
   End Sub

Private Sub Command3_Click()
   MultiMedia.mmOpen Res3
   MultiMedia.mmPlay
End Sub

Private Sub Form_Load()
   Res1 = "C:\windows\media\notify.wav"
   Res2 = "c:\windows\media\logoff.wav"
   Res3 = "c:\windows\media\chimes.wav"
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  MultiMedia.mmStop
   MultiMedia.mmClose
End Sub

You can Play , Wav,Midi and Avi Files
Hope it Suites You.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9053421
This question has been classified as abandoned.  I will make a recommendation to the moderators on its resolution in a week or two.  I would appreciate any comments by the experts that would help me in making a recommendation.

It is assumed that any participant not responding to this request is no longer interested in its final deposition.

If the asker does not know how to close the question, the options are here:
http://www.experts-exchange.com/help/closing.jsp

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9116219
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->Accept JoaTex's comment as Answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question