473,706 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Looking for code

Hi,
I am looking for code for a alarm clock program that pops up a messege to be
used as part of my VB.Net class project. Any help is very much appreciated.

Thanks
Nov 20 '05 #1
8 2499
Gumi:

I don't know of any project but I'm sure there is one. however, creating
this would be very easy depending on what you needed the clock to look
like...if it's a digital clock it'd be a piece of cake. Create a form or
usercontrol and drag a label onto it. Set the format specifier of the label
(or textbox) to Time or DateTime , basically whichever format you wanted.
You may want to create some properties that will allow the user to change
this .. Then I'd create an indexed property to hold the value of times you
wanted the thing to pop up at. You could also have a different property
that would cause it to alert every X minutes. You could use simple
division to implement this instead of the indexed properties b/c if you
wanted it to alert every five minutes, it'd be silly to store 24 hours worth
of 5 minute intervals in a property when division would do the trick a lot
easier. So depending on the user need you may want either or both..

Now, just spin off a background thread and check the times in the
property(ies) against the current system time DateTime.Now(); if there's a
match, show the form modally or run it as a control or notify icon, that
part depends on the use case but the logic is the same regardless. For set
intervals you could just use a Modulus or you could use a Greater than start
time and Less than end time and Not Already Shown type logic.

HTH,

Bill
"gumi" <gu**@abeys.com > wrote in message
news:TbCgc.5063 $uF3.2660@laker ead04...
Hi,
I am looking for code for a alarm clock program that pops up a messege to be used as part of my VB.Net class project. Any help is very much appreciated.
Thanks

Nov 20 '05 #2
Hi Gumi,

This is the most simple alarm clock, drag a normal timer, a textbox and a
button to your form and than in the code.
\\\
Private Sub Button1_Click_1 (ByVal _
sender As System.Object, ByVal e As _
System.EventArg s) Handles Button1.Click
Timer1.Interval = CInt(CDbl(TextB ox1.Text) * 1000)
Timer1.Enabled = True
End Sub
///
\\\
Private Sub Timer1_Tick(ByV al sender As System.Object, _
ByVal e As System.EventArg s) Handles Timer1.Tick
Timer1.Enabled = False
MessageBox.Show ("Time is expired")
End Sub
///
This is simple, for 1 second by second, you should take care the user can
only enter numbers.

To see a nice clock, you can look in the Resource kit at GDI
http://msdn.microsoft.com/vbasic/vbrkit/default.aspx

And if you have problems installing it
http://msdn.microsoft.com/vbasic/vbr...q/#installvdir

I hope this helps a little bit?

Cor


Nov 20 '05 #3
I don't know if this is what you're looking for, but it's an simple
example of an alarm, you just fill in the time and a message to be
displayed at that time and press activate. It's just something basic I
made 2 minutes ago, maybe it can help you.

copy and paste the following code:

Public Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows. Forms.Button
Friend WithEvents TextBox2 As System.Windows. Forms.TextBox
Friend WithEvents Label1 As System.Windows. Forms.Label
Friend WithEvents Label2 As System.Windows. Forms.Label
Friend WithEvents DateTimePicker1 As
System.Windows. Forms.DateTimeP icker
Friend WithEvents Timer1 As System.Windows. Forms.Timer
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.components = New System.Componen tModel.Containe r()
Me.Button1 = New System.Windows. Forms.Button()
Me.TextBox2 = New System.Windows. Forms.TextBox()
Me.Label1 = New System.Windows. Forms.Label()
Me.Label2 = New System.Windows. Forms.Label()
Me.DateTimePick er1 = New System.Windows. Forms.DateTimeP icker()
Me.Timer1 = New System.Windows. Forms.Timer(Me. components)
Me.SuspendLayou t()
'
'Button1
'
Me.Button1.Loca tion = New System.Drawing. Point(16, 136)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing. Size(168, 23)
Me.Button1.TabI ndex = 0
Me.Button1.Text = "activate"
'
'TextBox2
'
Me.TextBox2.Loc ation = New System.Drawing. Point(80, 104)
Me.TextBox2.Nam e = "TextBox2"
Me.TextBox2.Siz e = New System.Drawing. Size(88, 20)
Me.TextBox2.Tab Index = 2
Me.TextBox2.Tex t = ""
'
'Label1
'
Me.Label1.Locat ion = New System.Drawing. Point(16, 72)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing. Size(64, 24)
Me.Label1.TabIn dex = 3
Me.Label1.Text = "time"
'
'Label2
'
Me.Label2.Locat ion = New System.Drawing. Point(16, 104)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing. Size(64, 16)
Me.Label2.TabIn dex = 4
Me.Label2.Text = "message"
'
'DateTimePicker 1
'
Me.DateTimePick er1.Format =
System.Windows. Forms.DateTimeP ickerFormat.Tim e
Me.DateTimePick er1.Location = New System.Drawing. Point(80, 72)
Me.DateTimePick er1.Name = "DateTimePicker 1"
Me.DateTimePick er1.ShowUpDown = True
Me.DateTimePick er1.Size = New System.Drawing. Size(88, 20)
Me.DateTimePick er1.TabIndex = 5
'
'Timer1
'
Me.Timer1.Inter val = 1000
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(520, 333)
Me.Controls.Add Range(New System.Windows. Forms.Control()
{Me.DateTimePic ker1, Me.Label2, Me.Label1, Me.TextBox2, Me.Button1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click
Timer1.Enabled = True

End Sub

Private Sub Timer1_Tick(ByV al sender As Object, ByVal e As
System.EventArg s) Handles Timer1.Tick
If Date.Now.ToLong TimeString =
DateTimePicker1 .Value.ToLongTi meString Then
MsgBox(TextBox2 .Text.ToString, MsgBoxStyle.Inf ormation)
End If
End Sub
End Class

"William Ryan eMVP" <bi**@NoSp4m.de vbuzz.com> wrote in message news:<O8******* *******@TK2MSFT NGP09.phx.gbl>. ..
Gumi:

I don't know of any project but I'm sure there is one. however, creating
this would be very easy depending on what you needed the clock to look
like...if it's a digital clock it'd be a piece of cake. Create a form or
usercontrol and drag a label onto it. Set the format specifier of the label
(or textbox) to Time or DateTime , basically whichever format you wanted.
You may want to create some properties that will allow the user to change
this .. Then I'd create an indexed property to hold the value of times you
wanted the thing to pop up at. You could also have a different property
that would cause it to alert every X minutes. You could use simple
division to implement this instead of the indexed properties b/c if you
wanted it to alert every five minutes, it'd be silly to store 24 hours worth
of 5 minute intervals in a property when division would do the trick a lot
easier. So depending on the user need you may want either or both..

Now, just spin off a background thread and check the times in the
property(ies) against the current system time DateTime.Now(); if there's a
match, show the form modally or run it as a control or notify icon, that
part depends on the use case but the logic is the same regardless. For set
intervals you could just use a Modulus or you could use a Greater than start
time and Less than end time and Not Already Shown type logic.

HTH,

Bill
"gumi" <gu**@abeys.com > wrote in message
news:TbCgc.5063 $uF3.2660@laker ead04...
Hi,
I am looking for code for a alarm clock program that pops up a messege to

be
used as part of my VB.Net class project. Any help is very much

appreciated.

Thanks

Nov 20 '05 #4
I've changed my previous code a bit, now if you press activate the
message and time get added to a listbox so you can add multiple
messages, you can delete a warning from the listbox by selecting it
and pressing delete.

Public Class Form1
Inherits System.Windows. Forms.Form
Private intTeller As Integer
#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows. Forms.Button
Friend WithEvents TextBox2 As System.Windows. Forms.TextBox
Friend WithEvents Label1 As System.Windows. Forms.Label
Friend WithEvents Label2 As System.Windows. Forms.Label
Friend WithEvents DateTimePicker1 As
System.Windows. Forms.DateTimeP icker
Friend WithEvents Timer1 As System.Windows. Forms.Timer
Friend WithEvents ListBox1 As System.Windows. Forms.ListBox
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.components = New System.Componen tModel.Containe r()
Me.Button1 = New System.Windows. Forms.Button()
Me.TextBox2 = New System.Windows. Forms.TextBox()
Me.Label1 = New System.Windows. Forms.Label()
Me.Label2 = New System.Windows. Forms.Label()
Me.DateTimePick er1 = New System.Windows. Forms.DateTimeP icker()
Me.Timer1 = New System.Windows. Forms.Timer(Me. components)
Me.ListBox1 = New System.Windows. Forms.ListBox()
Me.SuspendLayou t()
'
'Button1
'
Me.Button1.Loca tion = New System.Drawing. Point(16, 136)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing. Size(168, 23)
Me.Button1.TabI ndex = 0
Me.Button1.Text = "activate"
'
'TextBox2
'
Me.TextBox2.Loc ation = New System.Drawing. Point(80, 104)
Me.TextBox2.Nam e = "TextBox2"
Me.TextBox2.Siz e = New System.Drawing. Size(88, 20)
Me.TextBox2.Tab Index = 2
Me.TextBox2.Tex t = ""
'
'Label1
'
Me.Label1.Locat ion = New System.Drawing. Point(16, 72)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing. Size(64, 24)
Me.Label1.TabIn dex = 3
Me.Label1.Text = "time"
'
'Label2
'
Me.Label2.Locat ion = New System.Drawing. Point(16, 104)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing. Size(64, 16)
Me.Label2.TabIn dex = 4
Me.Label2.Text = "message"
'
'DateTimePicker 1
'
Me.DateTimePick er1.Format =
System.Windows. Forms.DateTimeP ickerFormat.Tim e
Me.DateTimePick er1.Location = New System.Drawing. Point(80, 72)
Me.DateTimePick er1.Name = "DateTimePicker 1"
Me.DateTimePick er1.ShowUpDown = True
Me.DateTimePick er1.Size = New System.Drawing. Size(88, 20)
Me.DateTimePick er1.TabIndex = 5
'
'Timer1
'
Me.Timer1.Inter val = 1000
'
'ListBox1
'
Me.ListBox1.Loc ation = New System.Drawing. Point(224, 64)
Me.ListBox1.Nam e = "ListBox1"
Me.ListBox1.Siz e = New System.Drawing. Size(224, 95)
Me.ListBox1.Tab Index = 6
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(520, 333)
Me.Controls.Add Range(New System.Windows. Forms.Control()
{Me.ListBox1, Me.DateTimePick er1, Me.Label2, Me.Label1, Me.TextBox2,
Me.Button1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click

If TextBox2.Text = "" Then
MsgBox("Please enter a message")
Else
Timer1.Enabled = True
ListBox1.Items. Add(DateTimePic ker1.Value.ToLo ngTimeString
& " " & TextBox2.Text)
End If
End Sub

Private Sub Timer1_Tick(ByV al sender As Object, ByVal e As
System.EventArg s) Handles Timer1.Tick
For intTeller = 0 To ListBox1.Items. Count - 1
If Strings.Left(Li stBox1.Items(in tTeller), 8) =
Date.Now.ToLong TimeString Then
MsgBox(Strings. Right(ListBox1. Items(intTeller ),
Len(ListBox1.It ems(intTeller)) - 8), MsgBoxStyle.Inf ormation)
End If
Next
End Sub

Private Sub ListBox1_KeyDow n(ByVal sender As Object, ByVal e As
System.Windows. Forms.KeyEventA rgs) Handles ListBox1.KeyDow n
If e.KeyCode = Keys.Delete Then
ListBox1.Items. Remove(ListBox1 .SelectedItem)
End If
End Sub
End Class
"William Ryan eMVP" <bi**@NoSp4m.de vbuzz.com> wrote in message news:<O8******* *******@TK2MSFT NGP09.phx.gbl>. ..
Gumi:

I don't know of any project but I'm sure there is one. however, creating
this would be very easy depending on what you needed the clock to look
like...if it's a digital clock it'd be a piece of cake. Create a form or
usercontrol and drag a label onto it. Set the format specifier of the label
(or textbox) to Time or DateTime , basically whichever format you wanted.
You may want to create some properties that will allow the user to change
this .. Then I'd create an indexed property to hold the value of times you
wanted the thing to pop up at. You could also have a different property
that would cause it to alert every X minutes. You could use simple
division to implement this instead of the indexed properties b/c if you
wanted it to alert every five minutes, it'd be silly to store 24 hours worth
of 5 minute intervals in a property when division would do the trick a lot
easier. So depending on the user need you may want either or both..

Now, just spin off a background thread and check the times in the
property(ies) against the current system time DateTime.Now(); if there's a
match, show the form modally or run it as a control or notify icon, that
part depends on the use case but the logic is the same regardless. For set
intervals you could just use a Modulus or you could use a Greater than start
time and Less than end time and Not Already Shown type logic.

HTH,

Bill
"gumi" <gu**@abeys.com > wrote in message
news:TbCgc.5063 $uF3.2660@laker ead04...
Hi,
I am looking for code for a alarm clock program that pops up a messege to

be
used as part of my VB.Net class project. Any help is very much

appreciated.

Thanks

Nov 20 '05 #5
I have programmed an excellent timer. I now want to program a 24 hour alarm clock using the computer clock as the reference. DateTime gives me 12:00 midnight. How do I compare it to TimeOfDay (add subtract, greater than, less than) so that I can make a message,splash, etc come up? I keep getting the message: "operand - is not allowed for date to date.
Maybe change the DateTime,TimeOf Day to strings and then compare?
Nov 20 '05 #6
"Charles Watson" <an*******@disc ussions.microso ft.com> schrieb
I have programmed an excellent timer. I now want to program a 24 hour
alarm clock using the computer clock as the reference. DateTime gives
me 12:00 midnight. How do I compare it to TimeOfDay (add subtract,
greater than, less than) so that I can make a message,splash, etc
come up? I keep getting the message: "operand - is not allowed for
date to date." Maybe change the DateTime,TimeOf Day to strings and
then compare?


I'm not sure what's exactly your problem, but you can have a look at the
DateTime and TimeSpan data types and their members.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #7
jbw
i am trying to return the number of days/ months and years from an entered
date to today. i want to be able to add and subtract various dates. do you
know an simpler way?

Public Class Form1

Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Disp ose()

End If

End If

MyBase.Dispose( disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents MainMenu1 As System.Windows. Forms.MainMenu

Friend WithEvents MenuItem1 As System.Windows. Forms.MenuItem

Friend WithEvents MenuItem2 As System.Windows. Forms.MenuItem

Friend WithEvents monthBox As System.Windows. Forms.ComboBox

Friend WithEvents yearBox As System.Windows. Forms.ComboBox

Friend WithEvents dateBoxE As System.Windows. Forms.TextBox

Friend WithEvents currentdate As System.Windows. Forms.Label

Friend WithEvents dateBoxC As System.Windows. Forms.TextBox

Friend WithEvents dateEntered As System.Windows. Forms.Label

Friend WithEvents Button1 As System.Windows. Forms.Button

Friend WithEvents DateBoxD As System.Windows. Forms.TextBox

Friend WithEvents Button2 As System.Windows. Forms.Button

Friend WithEvents daysDiff As System.Windows. Forms.Label

Friend WithEvents monthDiff As System.Windows. Forms.Label

Friend WithEvents yearDiff As System.Windows. Forms.Label

Friend WithEvents dateBoxM As System.Windows. Forms.TextBox

Friend WithEvents dateBoxY As System.Windows. Forms.TextBox

Friend WithEvents mdy As System.Windows. Forms.Label

Friend WithEvents mdyBox As System.Windows. Forms.TextBox

Friend WithEvents daysBox As System.Windows. Forms.ComboBox

<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()

Me.MainMenu1 = New System.Windows. Forms.MainMenu( )

Me.MenuItem1 = New System.Windows. Forms.MenuItem( )

Me.MenuItem2 = New System.Windows. Forms.MenuItem( )

Me.monthBox = New System.Windows. Forms.ComboBox( )

Me.daysBox = New System.Windows. Forms.ComboBox( )

Me.yearBox = New System.Windows. Forms.ComboBox( )

Me.dateBoxE = New System.Windows. Forms.TextBox()

Me.currentdate = New System.Windows. Forms.Label()

Me.dateBoxC = New System.Windows. Forms.TextBox()

Me.dateEntered = New System.Windows. Forms.Label()

Me.Button1 = New System.Windows. Forms.Button()

Me.daysDiff = New System.Windows. Forms.Label()

Me.DateBoxD = New System.Windows. Forms.TextBox()

Me.Button2 = New System.Windows. Forms.Button()

Me.monthDiff = New System.Windows. Forms.Label()

Me.yearDiff = New System.Windows. Forms.Label()

Me.dateBoxM = New System.Windows. Forms.TextBox()

Me.dateBoxY = New System.Windows. Forms.TextBox()

Me.mdy = New System.Windows. Forms.Label()

Me.mdyBox = New System.Windows. Forms.TextBox()

Me.SuspendLayou t()

'

'MainMenu1

'

Me.MainMenu1.Me nuItems.AddRang e(New System.Windows. Forms.MenuItem( )
{Me.MenuItem1, Me.MenuItem2})

'

'MenuItem1

'

Me.MenuItem1.In dex = 0

Me.MenuItem1.Te xt = "&File"

'

'MenuItem2

'

Me.MenuItem2.In dex = 1

Me.MenuItem2.Te xt = "&Edit"

'

'monthBox

'

Me.monthBox.Loc ation = New System.Drawing. Point(72, 40)

Me.monthBox.Nam e = "monthBox"

Me.monthBox.Siz e = New System.Drawing. Size(121, 21)

Me.monthBox.Tab Index = 0

Me.monthBox.Tex t = "Month"

'

'daysBox

'

Me.daysBox.Loca tion = New System.Drawing. Point(224, 40)

Me.daysBox.Name = "daysBox"

Me.daysBox.Size = New System.Drawing. Size(121, 21)

Me.daysBox.TabI ndex = 1

Me.daysBox.Text = "Day"

'

'yearBox

'

Me.yearBox.Loca tion = New System.Drawing. Point(368, 40)

Me.yearBox.Name = "yearBox"

Me.yearBox.Size = New System.Drawing. Size(121, 21)

Me.yearBox.TabI ndex = 2

Me.yearBox.Text = "Year"

'

'dateBoxE

'

Me.dateBoxE.Loc ation = New System.Drawing. Point(232, 80)

Me.dateBoxE.Nam e = "dateBoxE"

Me.dateBoxE.Siz e = New System.Drawing. Size(144, 20)

Me.dateBoxE.Tab Index = 4

Me.dateBoxE.Tex t = "TextBox1"

'

'currentdate

'

Me.currentdate. Location = New System.Drawing. Point(104, 120)

Me.currentdate. Name = "currentdat e"

Me.currentdate. TabIndex = 5

Me.currentdate. Text = "current date"

Me.currentdate. TextAlign = System.Drawing. ContentAlignmen t.MiddleCenter

'

'dateBoxC

'

Me.dateBoxC.Loc ation = New System.Drawing. Point(232, 120)

Me.dateBoxC.Nam e = "dateBoxC"

Me.dateBoxC.Siz e = New System.Drawing. Size(144, 20)

Me.dateBoxC.Tab Index = 6

Me.dateBoxC.Tex t = "TextBox2"

'

'dateEntered

'

Me.dateEntered. Location = New System.Drawing. Point(104, 80)

Me.dateEntered. Name = "dateEntere d"

Me.dateEntered. TabIndex = 7

Me.dateEntered. Text = "Date entered:"

Me.dateEntered. TextAlign = System.Drawing. ContentAlignmen t.MiddleCenter

'

'Button1

'

Me.Button1.Loca tion = New System.Drawing. Point(416, 80)

Me.Button1.Name = "Button1"

Me.Button1.TabI ndex = 8

Me.Button1.Text = "Button1"

'

'daysDiff

'

Me.daysDiff.Loc ation = New System.Drawing. Point(80, 160)

Me.daysDiff.Nam e = "daysDiff"

Me.daysDiff.Siz e = New System.Drawing. Size(120, 23)

Me.daysDiff.Tab Index = 9

Me.daysDiff.Tex t = "date difference days"

Me.daysDiff.Tex tAlign = System.Drawing. ContentAlignmen t.MiddleCenter

'

'DateBoxD

'

Me.DateBoxD.Loc ation = New System.Drawing. Point(232, 160)

Me.DateBoxD.Nam e = "DateBoxD"

Me.DateBoxD.Siz e = New System.Drawing. Size(144, 20)

Me.DateBoxD.Tab Index = 10

Me.DateBoxD.Tex t = "TextBox3"

'

'Button2

'

Me.Button2.Loca tion = New System.Drawing. Point(416, 160)

Me.Button2.Name = "Button2"

Me.Button2.TabI ndex = 11

Me.Button2.Text = "Button2"

'

'monthDiff

'

Me.monthDiff.Lo cation = New System.Drawing. Point(80, 200)

Me.monthDiff.Na me = "monthDiff"

Me.monthDiff.Si ze = New System.Drawing. Size(120, 23)

Me.monthDiff.Ta bIndex = 12

Me.monthDiff.Te xt = "date difference months"

Me.monthDiff.Te xtAlign = System.Drawing. ContentAlignmen t.MiddleCenter

'

'yearDiff

'

Me.yearDiff.Loc ation = New System.Drawing. Point(80, 240)

Me.yearDiff.Nam e = "yearDiff"

Me.yearDiff.Siz e = New System.Drawing. Size(120, 23)

Me.yearDiff.Tab Index = 13

Me.yearDiff.Tex t = "date difference years"

Me.yearDiff.Tex tAlign = System.Drawing. ContentAlignmen t.MiddleCenter

'

'dateBoxM

'

Me.dateBoxM.Loc ation = New System.Drawing. Point(232, 200)

Me.dateBoxM.Nam e = "dateBoxM"

Me.dateBoxM.Siz e = New System.Drawing. Size(144, 20)

Me.dateBoxM.Tab Index = 14

Me.dateBoxM.Tex t = "TextBox4"

'

'dateBoxY

'

Me.dateBoxY.Loc ation = New System.Drawing. Point(232, 240)

Me.dateBoxY.Nam e = "dateBoxY"

Me.dateBoxY.Siz e = New System.Drawing. Size(144, 20)

Me.dateBoxY.Tab Index = 15

Me.dateBoxY.Tex t = "TextBox5"

'

'mdy

'

Me.mdy.Location = New System.Drawing. Point(64, 288)

Me.mdy.Name = "mdy"

Me.mdy.Size = New System.Drawing. Size(136, 23)

Me.mdy.TabIndex = 16

Me.mdy.Text = "months days years"

Me.mdy.TextAlig n = System.Drawing. ContentAlignmen t.MiddleCenter

'

'mdyBox

'

Me.mdyBox.Locat ion = New System.Drawing. Point(232, 288)

Me.mdyBox.Name = "mdyBox"

Me.mdyBox.Size = New System.Drawing. Size(144, 20)

Me.mdyBox.TabIn dex = 17

Me.mdyBox.Text = "TextBox6"

'

'Form1

'

Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)

Me.ClientSize = New System.Drawing. Size(576, 349)

Me.Controls.Add Range(New System.Windows. Forms.Control() {Me.mdyBox, Me.mdy,
Me.dateBoxY, Me.dateBoxM, Me.yearDiff, Me.monthDiff, Me.Button2,
Me.DateBoxD, Me.daysDiff, Me.Button1, Me.dateEntered, Me.dateBoxC,
Me.currentdate, Me.dateBoxE, Me.yearBox, Me.daysBox, Me.monthBox})

Me.Menu = Me.MainMenu1

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

monthBox.Items. Add("Jan")

monthBox.Items. Add("Feb")

monthBox.Items. Add("Mar")

monthBox.Items. Add("Apl")

monthBox.Items. Add("May")

monthBox.Items. Add("Jun")

monthBox.Items. Add("Jul")

monthBox.Items. Add("Aug")

monthBox.Items. Add("Sep")

monthBox.Items. Add("Oct")

monthBox.Items. Add("Nov")

monthBox.Items. Add("Dec")

Dim nDays As Short

For nDays = 1 To 31

daysBox.Items.A dd(nDays)

Next

Dim nYear As Short

For nYear = 1 To 115

yearBox.Items.A dd(nYear + 1900)

Next

End Sub

Private Sub dateBoxC_TextCh anged(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles dateBoxC.TextCh anged

dateBoxC.Text = DateString

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim eDate As String

eDate = ((1 + monthBox.Select edIndex) & "-" & (1 + daysBox.Selecte dIndex) &
"-" & _

(1901 + yearBox.Selecte dIndex))

dateBoxE.Text = eDate

End Sub

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click

Dim a, b, c, d, f, g As Integer

Dim ldm As Integer

Dim ldmm As Date

Dim x As Date

a = DateDiff("d", x, Now)

DateBoxD.Text = a

x = dateBoxE.Text

c = DateDiff("yyyy" , x, Now)

If (1 + monthBox.Select edIndex) > Val(Month(Now)) Then

c = c - 1

End If

dateBoxY.Text = c

b = DateDiff("m", x, Now)

dateBoxM.Text = b

'f = ((b / 12) - (Int(b / 12))) * 12

If (1 + monthBox.Select edIndex) = 2 Then

ldm = 28

ElseIf (1 + monthBox.Select edIndex) = 4 Then

ldm = 30

ElseIf (1 + monthBox.Select edIndex) = 6 Then

ldm = 30

ElseIf (1 + monthBox.Select edIndex) = 9 Then

ldm = 30

ElseIf (1 + monthBox.Select edIndex) = 11 Then

ldm = 30

Else : ldm = 31

End If

mdyBox.Text = ldmm



End Sub

End Class

"Armin Zingler" <az*******@free net.de> wrote in message
news:40******** *************** @news.freenet.d e...
"Charles Watson" <an*******@disc ussions.microso ft.com> schrieb
I have programmed an excellent timer. I now want to program a 24 hour
alarm clock using the computer clock as the reference. DateTime gives
me 12:00 midnight. How do I compare it to TimeOfDay (add subtract,
greater than, less than) so that I can make a message,splash, etc
come up? I keep getting the message: "operand - is not allowed for
date to date." Maybe change the DateTime,TimeOf Day to strings and
then compare?


I'm not sure what's exactly your problem, but you can have a look at the
DateTime and TimeSpan data types and their members.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #8
"jbw" <za*****@hotmai l.com> schrieb
i am trying to return the number of days/ months and years from an
entered date to today. i want to be able to add and subtract various
dates. do you know an simpler way?


Please post the relevant code only. If you paste the code in notepad first
and copy it from there to into your posting, no blank lines are inserted and
identation is kept unchanged.

Your code can not be compiled. First enable Option Strict in the project
properties. It shows some obvious errors.

As I said, have a look at the datetime and timespan structures and their
methods. Example:

dim d as date
dim diff as timespan

d = New Date(yearBox.Se lectedIndex + 1900, monthBox.Select edIndex + 1,
daysBox.Selecte dIndex + 1)
diff = d.subtract(date .now)

msgbox diff.totaldays

--
Armin

Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2686
by: Rick | last post by:
Hi all, I have recently been implementing php code in some web pages and am now looking for a more visual oriented php development environment because for example creating php/html forms by hand for the x'th time is not exactly my idea of working efficiently. (Unlike some guys i work with who seem to think this is an extremely cool working method. :-/) I'm looking for something with an interface like delphi or vb, and some of the more...
20
5136
by: Clark | last post by:
Hi all. I'm looking for good C source code to study and be able to advance my C programming skills. Do you recomend any open source project in particular that in your opinion has good writen C code? Thanks.
0
1108
by: JollyK | last post by:
Looking for opinion on code size for presention tier asp.net application. I have created a user-control that has a fairly complex datagrid which includes localization, custom paging, sorting, filtering, searching, caching, options to add, edit, and delete record, and then enabling and disabling links inside the datagrid based on different conditions. Everything is working fine now. I have hand-coded everything and the total length of my...
1
2583
by: Johann Blake | last post by:
I am looking for a good solution on how to implement data access in an application so that there is a clean separation between the data access layer, the business layer and the GUI layer. I am looking for a robust solution for a major application. Almost every developer seems to come up with a completely different solution. While many of them are not bad, I really want a very good one. My database is SQL Server 2000 and I am using Visual...
7
1758
by: Bruce HS | last post by:
I'd like to call my ancestor Validation Function every time any control on a Win Form generates a Validating or Validated event. I'm using VB. I've extended Textbox, for instance, to have its events do this for me, but my extended textbox doesn't get created by those wonderful form setup wizards. So, 1) Is there a way I can pick up these events without having to code for each control and without using custom extended controls, OR
1
3509
by: Sithlord999 | last post by:
Hello. I'm working on an email form on Dreamweaver and I'm looking for a PHP code to make it work. The form with some required fields would send the submitted information and two image attachments to my email address. I just started looking at PHP two weeks ago for an answer and the only code that worked for me, so far, was a simple php email form: <html> <head></head> <body> <? if(isset($submit)) { //check for email injection attack;...
11
2349
by: matsi.inc | last post by:
I am looking to make something like a delegate that i can use in my projects but am having a hard time getting started. The behavior I am most interested in is how a delegate changes it's Invoke method dynamically to match the arguments supplied to it when it is defined. For example... public delegate void MyDelegate(string myString, int myInt);
0
1995
by: AMDRIT | last post by:
I am looking for better concrete examples, as I am a bit dense, on design patterns that facilitate my goals. I have been out to the code project, planet source code, and microsoft's patterns and practices site and it just isn't sinking in all that clearly to me. Currently we have code in production and it all works well, however it is not the way we want it. We know that we can implement a better design plan to improve performance,...
6
2324
by: beantaxi | last post by:
Hello all, I'm looking for a very simple code analysis tool. I have a large codebase to analyze, and all I really need to do is to find all uses of all methods in a few interfaces. Many tools (e.g. Resharper) obviously do this internally, but I can't seem to find any that expose this simple functionality. Command line would be fine -- in fact I'd prefer that but its not necessary.
0
8773
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9276
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9042
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5935
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4705
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2495
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.