Library code snippets
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).
Related articles
Related discussion
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
listbox scrollbar
by Dennijr (10 replies)
-
Can you describe Above simple VB6 code?
by pramodmca09 (0 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
Hi my names chris barbour <bobjamin> and im new on this site but im far from new at programming ive programmed for about 6 or 7 years now and im 17 years old. I started with visual basic then moved to c++ and now i use C#, C# is a mixture between the two languages, it has the power of c++ and the simpleness of vb. about a month ago i realised you could use the beep function in vb to send a frequency and duration to the internal beeper and so naturally i played about with that. in C# the syntax is simple(Console.Beep(frequency,duration))and there is also a sleep function (System.threading.thread.Sleep(duration)), i used these to create a piano machine, it basically displays a piano onscreen with inputs for tempo,length of beat,file name and file path. every time you press a button it plays the corresponding beeps frequency.If the record checkbox is pressed then it writes to a file every notes length,frequency,starting position and ending position.Then if you click on left hand it alows you to write the left hand notes.Now when you press play it reads each file seperately and because you cant play two notes together it looks for the notes the cut each other at a point and it seperates them so it sounds like two notes are being played. This only really works for fast songs like fantasy impromptu which i think i put with the zip file(which i cant send here for some reason, if you want it email me at bobjamin@aol.com ill send you it free) because when long notes are played can then another note comes in it just stops. For that reason im trying to work with midis<if anyone can help please do,ive been trying to use the winmm.dll library but ive had no luck sounding anything> If i cant get that to work then im goin to work on a program that allows you to use the internal speaker like a normal speaker by sending 1 millisecond pulses at the right frequency to act like two simultaneos waves coming together. I can convert from visual basic easily so if you could send me anything that would help me get the midi situation sorted out then please send me it.
thanx!
Hi,
I have successfully get the beep sound out. However, how to display a form and then only the beep sound? Currently the beep sound is out before the form is displayed.Where should I put the this line : Beep 500, 9000 ?? If I were to put inside the form, then it will call the sound even before the form is displayed. Please advice.
Thanks.
Is it possible to make VB create two tones at the same time?
i am trying get a sound out of the internal pc speaker for 2 days and i am still trying. i have win 98, i consider myself prety advanced in vb language
. i searched more on google. i found a driver for pc speaker. it still didn't work
. i downloaded a program that said that it makes the internal speaker beep, but no, it made the same visual basic beep. whatever frequency or how many miliseconds i set for the beep its still makes the vb beep through my headphones.
can someone pls answer these problems?
I coded a simple program that makes different tones, the programs runs fine on users with windows xp, but it gives the same tone all the time with ppl running Windows 98, what can I do to give em all the tones
Are there values to control the interval between beeps and to control the volume of the beep?
Thanks,
David.
1) Create a new user (assuming you have admin auth)
2) As new user run regedit.
3) Expand HKEY_CURRENT_USER
4) Right click on HKEY_CURRENT_USER\AppEvents
5) Export as somefilename.reg
6) Log off new user and back on as original user
7) Double click somefilename.reg
8) Answer 'yes" to the prompt.
That's it; no re-boot or anything.
i would suggest opening a new .exe and just putting the command button in with just my source. i am not at all familiar with your instring declarations.
sorry i couldn't help more.
???s
* The beep() doc goes on and on about UIPermissions; any advice/thoughts here? If this were the issue I would think it would throw a runtime error, which it doesn't. Try/Catch caught nothing.
* Numerous of the "sound profile" settings in XP's setup are set to nothing. Does beep() use one of these (which)?
Any help appreciated.
=PDG=
---
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
Private Sub btnBeep_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBeep.Click
Beep(500, 1000)
MsgBox("Did the beep thing")
End Sub
End Class
---
I've made it a hobby of mine making up my own english...
Sowwy d00d
huh? is this english?
Tha a Lot Palley!
hey dzjowk,
i had the same problem. i figured it out. simply place the declare function .... line in your program declarations. it is not declared as a separate funciton. here's my code:
Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
Private Sub Command1_Click()
Beep 500, 100
End Sub
Hi,
I'm merely a N00b in VB-programming...
I tried docmd.beep for beeping on errors and such.
But as you said, this only works when there's a soundcard installed ánd speakers attached.
I tried to use your beep code, but I just can't seem to get it right.
declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
beep 500 1000
could U specify what comes where ?
(inside function, new function... ?)
Tha in Adva
This thread is for discussions of Make the PC beep.