Results 1 to 3 of 3

Thread: wav sound on button click problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2010
    Posts
    16

    wav sound on button click problem

    Hi

    I have bit of a problem, I am trying to use sound after the button is cliecked. However it does not work and it doesn't pick up the wav saund as the previous statment is wrong can you please help me out with it and make the sound work.
    Code:
    Option Explicit
    Private Declare Function sndplaysound Lib "winmm.dll" Alias "sndplaysounda" _
        (ByVal lpszsoundname As String, ByVal uflags As Long) As Long
        Const snd_sunc = &H0
        Const snd_async = &H1
        Const snd_nodefault = &H2
        Const snd_loop = &H8
        Const snd_nostop = &H10
        
       
       
        
    Dim i As Byte 'numbers in range
    Dim lTemp As Byte
    Dim iOuter As Byte
    Dim iInner As Byte
    Dim lowest As Byte
    Dim highest As Byte
    Dim lUpper As Byte, lLower As Byte
    Dim lRandom As Byte, lQuantity As Byte, lStart As Byte, lEnd As Byte
    Dim itemp As Byte
    
    Private numbers_Array() As Integer
    Private Sub cmdGenerate_Click()
        
    'set the variables
    lQuantity = 6
    lStart = 1
    lEnd = 49
    
    
    
        
    'Initialize varaibles.
        ReDim numbers_Array(1 To 49)
        lowest = LBound(numbers_Array()) 'returns the lowest value declared in the arroy = 1
        highest = UBound(numbers_Array()) 'returns the highest value declated in the arroy = 49
    'Fill array with numbers in range from 1 to 49.
        For i = lowest To highest
            numbers_Array(i) = i + 1
        Next i
    'do no repeat values, no duplications
        For i = lowest To highest
            'Save the current numbers
                lTemp = numbers_Array(i)
            'Get another random number
                lRandom = Int(Rnd * (highest - lowest)) + 1
            'Swap the numbers
                numbers_Array(i) = numbers_Array(lRandom)
                numbers_Array(lRandom) = lTemp
        Next i
    
    'Sorting for display
        lowest = LBound(numbers_Array)
        highest = UBound(numbers_Array)
        
        'Which bubbling pass
        For iOuter = lowest To highest - 1
            'Which comparison
            For iInner = lStart To lQuantity
            
                'Compare this item to the next item
                If numbers_Array(iInner) > numbers_Array(iInner + 1) Then
                    'swaping and sorting values according
                    itemp = numbers_Array(iInner)
                    numbers_Array(iInner) = numbers_Array(iInner + 1)
                    numbers_Array(iInner + 1) = itemp
                End If
                
            Next iInner
        Next iOuter
    'move simulated numbers to labels
    For i = 0 To (lQuantity - 1)
        lblNumber(i).Caption = numbers_Array(i + 1)
    Next i
        
        soundfile$ = "K:\year 2\even driven\assignment3\garfield.wav"
        wflags% = snd_async Or snd_nodefault
        sound = sndplaysound(soundlike$, wflags%)
    
    End Sub
    the error comes up when we come to soundfile$ line PLEASE help
    Thanks

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: wav sound on button click problem

    When you mention errors, always tell us what the error is specifically.

    I suspect it is that you didn't declare/dim soundfile$. Start your app by pressing Ctrl+F5 and fix any immediate errors VB warns you about.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

Posting Permissions

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



Click Here to Expand Forum to Full Width