Make the PC beep

It would appear at first that VB's standard Beep function would do just this. However, if a sound card is installed, even if the speakers are turned off, they will be used instead. To force the PC's internal speaker to sound, you need to use the Windows API beep function. Using this, you can even set the pitch and length of the beep.

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

To sound the beeper, simply use

Beep 500, 1000

The first value sets the frequency (or pitch). I find my PC's beeper performs best in the 500-3000 range. The second value is the duration of the beep in milliseconds (so 1000 is one second).

You might also like...

Comments

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Better train people and risk they leave – than do nothing and risk they stay.” - Anonymous