Introduction
This is my first program which is made by Visual Basic.Net, It was fantastic to feel that you are programming
a program, my program is a Small Alarm, by this program you can type the time when you want to run the tone, you
also can assign a tone which you want to use, it is a small alarm for the users, but it was very big and difficult for me.
The Problems I Got
During the programming, I got many problems with this program, but I could solve all that by thinking, the great
problem which I got was how to compare the time which entered by the user with the currently time, all developers
know that I can't use a public variable in any sub, so it
was really great problem, but I solved it by using the variable as friend in the class , it was so difficult to use it when
it is in the class, but I could, another problem was
to use DateTime object but I solved it by made own class which include three fields and one sub and one
functions, it took much time to got the solution
but it was fantastic.
Form1 Code
Imports Microsoft.Win32
Imports System.TimeSpan
Imports NTime
Public Class Form1
Public a, b As New NTime.NTime
Public Bool As Boolean
Public R As RegistryKey = Registry.CurrentUser
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
e.Cancel = True
Tray()
NotifyIcon1.ShowBalloonTip(5, "Small Alarm", "Small Alarm wasn't closed", ToolTipIcon.Info)
Timer1.Enabled = False
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
NotifyIcon1.Visible = False
Dim R As RegistryKey = Registry.CurrentUser
R.CreateSubKey("SmallAlarm")
Timer1.Interval = 1000
Timer1.Enabled = True
If R.OpenSubKey("SmallAlarm", True).GetValue("Tone") = "" Then
MessageBox.Show("You must select tone via the options", "Tone Select", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Exit Sub
End If
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
Me.Show()
NotifyIcon1.Visible = False
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Friend Sub Tray()
NotifyIcon1.ContextMenuStrip = ContextMenuStrip1
Me.Hide()
NotifyIcon1.Icon = Me.Icon
NotifyIcon1.Text = "Small Alarm"
NotifyIcon1.Visible = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Tray()
NotifyIcon1.ShowBalloonTip(5, "Small Alarm", "Click on the icon to show the options", ToolTipIcon.Info)
Timer1.Enabled = False
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Form2.ShowDialog()
Timer1.Enabled = False
End Sub
Private Sub TabPage1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabPage1.Enter
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub TabPage1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabPage1.Leave
Timer1.Enabled = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
TextBox1.Text = Date.Now
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim Time As Date = Date.Now
a.Hour = Time.Hour
a.Minute = Time.Minute
a.Second = Time.Second
Bool = b.Compare(a, b)
If Bool = True Then
W.URL = R.OpenSubKey("SmallAlarm", True).GetValue("Tone")
Timer2.Enabled = False
TextBox3.ReadOnly = False
TextBox4.ReadOnly = False
TextBox5.ReadOnly = False
Button6.Enabled = False
Button4.Enabled = True
End If
End Sub
Private Sub Button5_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If R.OpenSubKey("SmallAlarm", True).GetValue("Tone") = "" Then
MessageBox.Show("You must select tone via the options", "Tone Select", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
If IsNumeric(TextBox3.Text) = True And IsNumeric(TextBox4.Text) = True And IsNumeric(TextBox5.Text) = True Then
b.Hour = Convert.ToInt32(TextBox3.Text)
b.Minute = Convert.ToInt32(TextBox4.Text)
b.Second = Convert.ToInt32(TextBox5.Text)
Timer2.Interval = 1000
Timer2.Enabled = True
TextBox3.ReadOnly = True
TextBox4.ReadOnly = True
TextBox5.ReadOnly = True
Button6.Enabled = True
Button4.Enabled = False
Else
MessageBox.Show("You entered wrong value(s)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
End Sub
Private Sub Button4_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
W.URL = ""
Button4.Enabled = False
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Timer2.Enabled = False
TextBox3.ReadOnly = False
TextBox4.ReadOnly = False
TextBox5.ReadOnly = False
Button6.Enabled = False
Button4.Enabled = False
End Sub
Private Sub ShowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowToolStripMenuItem.Click
Me.Show()
NotifyIcon1.Visible = False
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub
End Class
Form2 Code
Imports Microsoft.Win32
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim R As RegistryKey = Registry.CurrentUser
TextBox1.Text = R.OpenSubKey("SmallAlarm").GetValue("Tone")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim F As New OpenFileDialog()
F.Filter = ("MusicFiles|*.WMV")
F.FileName = ""
F.ShowDialog()
TextBox1.Text = F.FileName
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim R As RegistryKey = Registry.CurrentUser
R.OpenSubKey("SmallAlarm", True).SetValue("Tone", TextBox1.Text)
Form1.Timer1.Interval = 1000
Form1.Timer1.Enabled = True
Me.Close()
End Sub
End Class
Features I Used
It was a problem to use a data base to store the URL of the tone, but I used the registry to store it, and I also used tray system.
The End
At the end of this article, I hope to see feedbacks and suggestions.
Nabil Ismail El-Esawy