I'm going to show how to create a simple egg timer in VB.Net.
First create a new application and rename the form to frmMain.
Add 3 NumbericUpDowns and change this:
First:
Name = "nudHours"
Maximum = "23"
Second:
Name = "nudMinutes"
Maximum = "59"
Third:
Name = "nudSeconds"
Maximum = "59"
Then add 2 buttons:
First:
Name = "btnStart"
Text = "Start"
Second:
Name = "btnReset"
Text = "Reset"
Then we need the timer to keep track of the time:
Name = "tmrTick"
Interval = "1000"
Now when the items are out we want to start with the code 
First we creates a handle for tmrTick.tick:
Code:
Private Sub tmrTick_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrTick.Tick
If nudSeconds.Value <> 0 Then
nudSeconds.Value -= 1
Else
If nudMinutes.Value <> 0 Then
nudMinutes.Value -= 1
nudSeconds.Value = 59
Else
If nudHours.Value <> 0 Then
nudHours.Value -= 1
nudMinutes.Value = 59
nudSeconds.Value = 59
Else
tmrTick.Enabled = False
btnStart.Text = "Start"
'What you want should happend when the time is up
End If
End If
End If
End Sub
What it does is to decrease the seconds if that is possible else it tries to decrease the minutes and the the hours, if all this is 0 it know the time has ended and it resets the timer and the start button.
Examples on what you can add on the commented line:
Just as single beep:
Shutdown the computer:
Code:
Process.Start("shutdown", "/s")
Starting a program:
Code:
Process.Start("The Path")
Playing music:
Code:
My.Computer.Audio.Play("The Path")
or
Code:
mciSendString("close audio", CStr(0), 0, 0)
mciSendString("Open " & Chr(34) & "The Path" & Chr(34) & " alias audio", CStr(0), 0, 0)
mciSendString("play audio", CStr(0), 0, 0)
With the second alternative you need to declare this:
Code:
Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
The second alternative can play more then just .wav files.
Now when we have the timer done we need to create handlers for the click event of the two buttons, first the btnStart:
Code:
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
tmrTick.Enabled = Not tmrTick.Enabled
If btnStart.Text = "Start" Then
btnStart.Text = "Pause"
Else
btnStart.Text = "Start"
End If
End Sub
This will make the timer start and stop.
And then to the btnReset so we can reset all info:
Code:
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
nudHours.Value = 0
nudMinutes.Value = 0
nudSeconds.Value = 0
tmrTick.Enabled = False
End Sub
If your program plays a sound when it finish remember to make it stop in this sub.
That's all, take care
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum