Click here to Skip to main content
15,885,365 members
Articles / Programming Languages / Visual Basic
Article

Small Alarm,Programmed By VB.NET

Rate me:
Please Sign up or sign in to vote.
3.16/5 (15 votes)
18 Mar 2008CDDL1 min read 61K   4.9K   37   5
my first program.

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


<p></p><p>


	</p><h2>Features I Used</h2><p>
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.
</p><p>

	</p><h2>The End</h2><p>
At the end of this article, I hope to see feedbacks and suggestions.

Nabil Ismail El-Esawy</p>

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


Written By
Other HOME
Egypt Egypt
My name is Nabil Isamil El-Esawy
I am a developer
I start programming since just one year
I learned VB6,VB.NET
For communication
nma202000@msn.com

Comments and Discussions

 
QuestionAdd more alarm time Pin
djtechwork7-Jan-12 8:10
djtechwork7-Jan-12 8:10 
Generalpostive replies or don't say anything at all!! Pin
Jason Yousef30-Jul-10 15:10
Jason Yousef30-Jul-10 15:10 
GeneralFantastic! But... Pin
trobertz18-Mar-08 11:22
trobertz18-Mar-08 11:22 
GeneralRe: Fantastic! But... Pin
nma20200018-Mar-08 12:38
nma20200018-Mar-08 12:38 
GeneralRe: Fantastic! But... Pin
James Garner (jadaradix)23-Jul-08 17:13
James Garner (jadaradix)23-Jul-08 17:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.