This is a very simple code, which will check every second if the time is the specified time.
Place two trackbars, a timer, a label and a button.
1. trackbar
Set the minimum to zero, and max. to 24.
2. trackbar
Set the minimum to zero, and max to 60.
The timer
It should be off by default, and the time intervall should be somewhere between
1000 (A second) and 59000 (59 seconds). I set mine at one second.
And the button,
which basicly will be the on button. Set it up as you want.
------------ The code -----------
Now, at first, just let me say that I got no idea how a 'professional' would do this,
I am writing this guide so I can get feedback for my coding style, not to tell
what is right and wrong.
Right under "public class form1", write
This will create two variables, which only accepts numbers.Code:Dim thehour As Integer Dim theminute As Integer
Forexample, I can store 24, and 14 in them, but not twentyfour, or fourteen.
And the most important part, the timer.
Every time the timer "ticks", this code will run.
Basicly, it will check if the time we currently have match what the alarm is set to
go off at.
The if statement will check if the time matches the variable "theour", and theCode:If TimeOfDay.Hour = (thehour) And TimeOfDay.Minute = (theminute) Then Process.Start("Countdown") Me.Close() End If
time match "theminute".
Where I have "process.start(""), you can have whatever you want to happen
when the alarm goes off to do. If you want a beep, you can write
Media.SystemSounds.Beep.Play()
I have chosen to make it start a second program with my alarm sounds and stuff,
it's easy to set up.
But, we need to set the value of our variables, and that's where the trackbars
come in.
The first one, with the settings 0-24, is obviously for hours, while the 1-60 is for
minutes.
So, double click on the hour trackbar, and write
Now I've started to use the textbox, to show when the alarm will go off.Code:thehour = TrackBar1.Value() TextBox1.Text = ("H" & thehour & " M" & theminute & " ")
It is both rather self explainatory. If it is set to go off at 12:30, the textbox
will display "H12 M30".
Now, what's left, is to make the button start the timer, and that should be it.
Some hints:
Set the textbox to not be editable, it may be confusing.
Set the button to hide the trackbars and button, perhaps make it display
a button which can turn the alarm off...
To make it beep, make it start another timer when it goes off, and make it
beep every second or so.
I hope someone will learn anything from this tutorial!
An example project will be uploaded soon, writing this in class. >.<