Results 1 to 3 of 3

Thread: Continuous Beep program

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    26

    Continuous Beep program

    I'm using the Beep function in kernel32.

    Public Declare Function Beep Lib "kernel32" _
    (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long

    I use the code Beep 1000, 1000

    But the problem is I want the beep to be continuous until a command button is pressed and the beep stops. How do I use the beep function to do this?

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Continuous Beep program

    A loop?????

  3. #3
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Continuous Beep program

    Beep in synchronous, so if its set to run for a second you can't just stop it until that duration is done, hence there will be a delay after you hit the stop button depending on how much duration of the beep is left.

    add a public variable as a stop flag to the module,
    Public StopBeep As Boolean

    In your form you could maybe do this,
    Code:
    Private Sub Command1_Click()
        ' start beep
        StopBeep = False
        Do
            DoEvents
            If StopBeep = True Then Exit Do
            Beep 1000, 1000
        Loop
    
    End Sub
    
    Private Sub Command2_Click()
        ' stop beep
        StopBeep = True
    End Sub

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