Practical Web Programming

Monday, September 17, 2007

How to Make Your PC Beep in Visual Basic

Making your PC beep in Visual Basic is relatively easy using API.

The source codes below is a reusable procedure to make your PC beep. This uses an API function and written in Visual Basic 6.

'Procedure: BeepPC
'Language: Visual Basic 6
'Parameter: None
'Purpose: This procedure uses an API function to beep the PC.
' The beeping sound is like error beep codes in your PC.
'Usage: Call BeepPC

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

Public Sub BeepPC()
Dim Cntr As Long
For Cntr = 0 To 5
Beep 700 * Cntr + 50, 1
DoEvents
Next Cntr
End Sub

3 comments:

Anonymous said...

Compiler Error:

Constants, fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules.

Anonymous said...

If you need a beep from your system speaker, there is no need to run or compile any garbage, just open a command prompt, press Ctrl+G and press enter.

Happy beeping!

Joel Badinas said...

@ Anonymous said... Compiler Error:

Take note that the code is for VB6 not VB.Net. To use, put it all in a module, then call the BeepPC function in your form. Work fine with me.

Recent Post