I will show you how to make a simple beeping application. you can customize the Frequency and Length of the beep to suit your needs and then play it with a simple line of code.
Start a new project (or add to an existing one) and just make a simple form with a button on it. I will leave the default name of Button1 on this button. I made the form look a little better but that's not necessary.
Now we are going to go to Code View. First, we need to have Imports System.Runtime.InteropServices right up the top there, above where it says Public Class Form1.
Next we have this little chunk of code here:
<DllImport("KERNEL32.DLL", EntryPoint:="Beep", SetLastError:=True, _ CharSet:=CharSet.Unicode, ExactSpelling:=True, _ CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function _ aBeep(ByVal dwFreq As Integer, ByVal dwDuration As Integer) _ As Boolean End Function
This imports KERNEL32.DLL (obviously) and sets up the function that makes the beep based on what's in the file. This all goes underneath Public Class Form1 so that your code should look like this:
Imports System.Runtime.InteropServices Public Class Form1 <DllImport("KERNEL32.DLL", EntryPoint:="Beep", SetLastError:=True, _ CharSet:=CharSet.Unicode, ExactSpelling:=True, _ CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function _ aBeep(ByVal dwFreq As Integer, ByVal dwDuration As Integer) _ As Boolean End Function End Class
Now go back into the Form Designer and Double Click on the Button you made, which will bring you back to the code window with a new button_Clicked Sub. In that sub, write aBeep(1000, 1000) and Debug your app. Click the button and enjoy the sound of Progress
*Beware: progress can be loud so turn the volume down!*
You should hear a plain and simple beep. Now to customise it.
You may have noticed that aBeep(1000, 1000) has two integer values. The first one is used for Frequency and the Second for Length. Length is measured in Milliseconds, meaning the current beep lasts for one second. Frequency is measured in Hz, so the noise you hear is at 1kHz (1000Hz) you can very easily change these numbers to change the sound. You can also use variables to make it a bit customisable for users too. For Example, I made a simple program that allows you to change the length/frequency on the spot.
I simply replaced the numbers in the aBeep function with my own variables.
*BEWARE* Windows will NOT stop you from setting the frequency too high or low. PLEASE be careful when messing around with the frequency of the beep because setting it to high or low could possible blow your speakers or even cause damage to your ears. Also, when playing the beep, the application will not move at all, so be careful when setting longer lengths.
I hope that this tutorial could help you