+ Reply to Thread
Results 1 to 8 of 8

Adding Sound to Program Revisited

  1. #1
    Carlton Patterson
    Guest

    Adding Sound to Program Revisited

    Hello all,

    I chap called Bob Phillips assisted me in adding sound to a program,
    however when I tried to create my own program with sound it wouldn't
    work. I was wondering if someone here could point out where I might be
    going wrong. I keep on getting the error message : Sub or Function not
    defined. I think its because I somehow haven't declared "playwavfile"
    but I'm not sure. Any help would be appreciated.

    Private Sub Worksheet_Calculate()
    Static prevValue
    If Range("I1").Value > prevValue Then
    PlayWavFile "C:\Windows\Media\Windows XP Print complete"
    prevValue = Range("I1").Value
    End If
    End Sub

    Cheers

    Carlton

    *** Sent via Developersdex http://www.developersdex.com ***

  2. #2
    Bob Phillips
    Guest

    Re: Adding Sound to Program Revisited

    Where have you stored the PlayWav File function? It, and the API
    declaration, should be in the same module as the call, or as Public
    definitions in a standard code module.

    --
    HTH

    Bob Phillips

    "Carlton Patterson" <[email protected]> wrote in message
    news:Of%[email protected]...
    > Hello all,
    >
    > I chap called Bob Phillips assisted me in adding sound to a program,
    > however when I tried to create my own program with sound it wouldn't
    > work. I was wondering if someone here could point out where I might be
    > going wrong. I keep on getting the error message : Sub or Function not
    > defined. I think its because I somehow haven't declared "playwavfile"
    > but I'm not sure. Any help would be appreciated.
    >
    > Private Sub Worksheet_Calculate()
    > Static prevValue
    > If Range("I1").Value > prevValue Then
    > PlayWavFile "C:\Windows\Media\Windows XP Print complete"
    > prevValue = Range("I1").Value
    > End If
    > End Sub
    >
    > Cheers
    >
    > Carlton
    >
    > *** Sent via Developersdex http://www.developersdex.com ***




  3. #3
    Carlton Patterson
    Guest

    Re: Adding Sound to Program Revisited

    Hi Bob,

    I didn't realise it needed to be stored - the file is in the directory
    specified in the program.

    I'm not sure how to declare a function.

    Could you provide another example?

    Cheers


    Carlton

    *** Sent via Developersdex http://www.developersdex.com ***

  4. #4
    Bob Phillips
    Guest

    Re: Adding Sound to Program Revisited

    Carlton,

    I will re-state the code.

    Make sure that all of this code is stored in the worksheet code module of
    the sheet that you will be testing I1 value. To do ths, right-click on the
    sheet tab, select the View Code option from the menu, and paste the code in.

    And also check that this file C:\Windows\Media\Microsoft Office
    2000\Chimes.wav exists at this location on your machine, or change
    accordingly.

    Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
    (ByVal lpszName As String, _
    hModule As Long, _
    ByVal dwFlags As Long) As Long

    Private Sub Worksheet_Calculate()
    If Range("I1").Value > 0 Then
    PlayWavFile "C:\Windows\Media\Microsoft Office 2000\Chimes.wav"
    End If
    End Sub


    Public Function PlayWavFile(WavFile As String) As String
    Const SND_ASYNC = &H1
    Const SND_FILENAME = &H20000
    PlaySound WavFile, 0, SND_ASYNC Or SND_FILENAME
    PlayWavFile = ""
    End Function


    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Carlton Patterson" <[email protected]> wrote in message
    news:[email protected]...
    > Hi Bob,
    >
    > I didn't realise it needed to be stored - the file is in the directory
    > specified in the program.
    >
    > I'm not sure how to declare a function.
    >
    > Could you provide another example?
    >
    > Cheers
    >
    >
    > Carlton
    >
    > *** Sent via Developersdex http://www.developersdex.com ***




  5. #5
    Carlton Patterson
    Guest

    Re: Adding Sound to Program Revisited

    OK,

    I'm trying to sort this out myself but still need your help.

    I downloaded the following program:

    Private Declare Function PlaySound Lib "winmm.dll" _
    Alias "PlaySoundA" (ByVal lpszName As String, _
    ByVal hModule As Long, ByVal dwFlags As Long) As Long

    Const SND_SYNC = &H0
    Const SND_ASYNC = &H1
    Const SND_FILENAME = &H20000

    Sub PlayWAV()
    WavFile = "chimes.wav"
    WavFile = "C:\WINDOWS\Media\chimes.wav"
    Call PlaySound(WavFile, 0&, SND_ASYNC Or SND_FILENAME)
    End Sub


    Can someone please help me incorporate the above into;

    Private Sub Worksheet_Calculate()
    Static prevValue
    If Range("I1").Value > prevValue Then
    prevValue = Range("I1").Value
    End If
    End Sub


    Cheers

    Carlton

    *** Sent via Developersdex http://www.developersdex.com ***

  6. #6
    Tom Ogilvy
    Guest

    Re: Adding Sound to Program Revisited

    Private Declare Function PlaySound Lib "winmm.dll" _
    Alias "PlaySoundA" (ByVal lpszName As String, _
    ByVal hModule As Long, ByVal dwFlags As Long) As Long

    Const SND_SYNC = &H0
    Const SND_ASYNC = &H1
    Const SND_FILENAME = &H20000

    Sub PlayWAV()
    WavFile = "chimes.wav"
    WavFile = "C:\WINDOWS\Media\chimes.wav"
    Call PlaySound(WavFile, 0&, SND_ASYNC Or SND_FILENAME)
    End Sub

    Private Sub Worksheet_Calculate()
    Static prevValue
    If Range("I1").Value > prevValue Then
    prevValue = Range("I1").Value
    PlayWav
    End If
    End Sub

    The end result is that your sheet module should look the same as if you
    copied all the above code and pasted it into an empty sheet module


    --
    Regards,
    Tom Ogilvy


    "Carlton Patterson" <[email protected]> wrote in message
    news:[email protected]...
    > OK,
    >
    > I'm trying to sort this out myself but still need your help.
    >
    > I downloaded the following program:
    >
    > Private Declare Function PlaySound Lib "winmm.dll" _
    > Alias "PlaySoundA" (ByVal lpszName As String, _
    > ByVal hModule As Long, ByVal dwFlags As Long) As Long
    >
    > Const SND_SYNC = &H0
    > Const SND_ASYNC = &H1
    > Const SND_FILENAME = &H20000
    >
    > Sub PlayWAV()
    > WavFile = "chimes.wav"
    > WavFile = "C:\WINDOWS\Media\chimes.wav"
    > Call PlaySound(WavFile, 0&, SND_ASYNC Or SND_FILENAME)
    > End Sub
    >
    >
    > Can someone please help me incorporate the above into;
    >
    > Private Sub Worksheet_Calculate()
    > Static prevValue
    > If Range("I1").Value > prevValue Then
    > prevValue = Range("I1").Value
    > End If
    > End Sub
    >
    >
    > Cheers
    >
    > Carlton
    >
    > *** Sent via Developersdex http://www.developersdex.com ***




  7. #7
    Carlton Patterson
    Guest

    Re: Adding Sound to Program Revisited

    OK,

    while waiting for help I put this together but still couldn't get the
    sound to work!

    Private Declare Function PlaySound Lib "winmm.dll" _
    Alias "PlaySoundA" (ByVal lpszName As String, _
    ByVal hModule As Long, ByVal dwFlags As Long) As Long

    Const SND_SYNC = &H0
    Const SND_ASYNC = &H1
    Const SND_FILENAME = &H20000

    Sub PlayWAV()

    WavFile = "chimes.wav"
    WavFile = "C:\WINDOWS\Media\chimes.wav"
    Call PlaySound(WavFile, 0&, SND_ASYNC Or SND_FILENAME)
    End Sub

    Private Sub Worksheet_Calculate()
    Static prevValue
    If Range("I1").Value > prevValue Then
    WavFile = "chimes.wav"
    WavFile = "C:\WINDOWS\Media\chimes.wav"
    Call PlaySound(WavFile, 0&, SND_ASYNC Or SND_FILENAME)
    prevValue = Range("I1").Value
    End If
    End Sub


    Carlton

    *** Sent via Developersdex http://www.developersdex.com ***

  8. #8
    Tom Ogilvy
    Guest

    Re: Adding Sound to Program Revisited

    Your code worked fine for me. (it performed as I would expect based on how
    it is written).

    Do you have the code in the sheet module?

    Is your sound turned on?

    Is the value in I1 of the sheet containing the code increasing?

    Is calculation set to automatic?

    --
    Regards,
    Tom Ogilvy


    "Carlton Patterson" <[email protected]> wrote in message
    news:%[email protected]...
    > OK,
    >
    > while waiting for help I put this together but still couldn't get the
    > sound to work!
    >
    > Private Declare Function PlaySound Lib "winmm.dll" _
    > Alias "PlaySoundA" (ByVal lpszName As String, _
    > ByVal hModule As Long, ByVal dwFlags As Long) As Long
    >
    > Const SND_SYNC = &H0
    > Const SND_ASYNC = &H1
    > Const SND_FILENAME = &H20000
    >
    > Sub PlayWAV()
    >
    > WavFile = "chimes.wav"
    > WavFile = "C:\WINDOWS\Media\chimes.wav"
    > Call PlaySound(WavFile, 0&, SND_ASYNC Or SND_FILENAME)
    > End Sub
    >
    > Private Sub Worksheet_Calculate()
    > Static prevValue
    > If Range("I1").Value > prevValue Then
    > WavFile = "chimes.wav"
    > WavFile = "C:\WINDOWS\Media\chimes.wav"
    > Call PlaySound(WavFile, 0&, SND_ASYNC Or SND_FILENAME)
    > prevValue = Range("I1").Value
    > End If
    > End Sub
    >
    >
    > Carlton
    >
    > *** Sent via Developersdex http://www.developersdex.com ***




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1