We help IT Professionals succeed at work.
Get Started

How do I stop a PlaySound call that continues output outside the logic of the program that called it?

spc909
spc909 asked
on
425 Views
Last Modified: 2012-05-09
Below code executes correctly up to the 1st instance that should produce sound.  That is the 12th bar of the 5th cycle.  Problem is that once the sound is called the 1st time . . . it continues to sound every bar thereafter, even though the code shows it is clearly a one time event.

For C = 1 To CycPhase
        iCycStart = (AncDyBar + 1)
        iCycEnd = (AncDyBar + (CycLength - 1))      
       pBarCnt = 0
        '*********** Next I Sequence **************
        For i = iCycStart To iCycEnd
            pBarCnt = pBarCnt + 1
            '        PlayNow = PlaySound(Null, 0, 0)  'Commented out because does not work
            If pBarCnt = 12 Then
                v1(z1, i) = Bar(2, i)
                If C = 5 Then     '5th cycle
                    PlayNow = PlaySound(A, p, SND_FILENAME Or SND_ASYNC Or SND_NOWAIT)
                End If
            End If
        Next i
        AncDyBar = i
    Next C

I've tried SndPurge and the Null string as shown commented out above.  The null string stops the dll from working  altogether and the SndPurge does nothing . . . and nothing stops a repeating call to the wav file.  Below is further information to help.

Public Declare Function PlaySound _
               Lib "winmm.dll" _
               Alias "PlaySoundA" (ByVal lpszName As String, _
                                   ByVal hModule As Long, _
                                   ByVal dwFlags As Long) As Long
Public Const SND_FILENAME = &H20000     'name is a file name
Public Const SND_ASYNC = &H1                 'play asynchronously
Public Const SND_NOWAIT = &H2000          'don't wait if the driver is busy
Public Const SND_PURGE = &H40                'stop sound (longer wav)

Thank You,
spc909
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 2 Answers and 7 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE