Looking for code

  • Thread starter Thread starter gumi
  • Start date Start date
G

gumi

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
 
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
 
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.EventArgs) Handles Button1.Click
Timer1.Interval = CInt(CDbl(TextBox1.Text) * 1000)
Timer1.Enabled = True
End Sub
///
\\\
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) 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/vbrkit/faq/#installvdir

I hope this helps a little bit?

Cor
 
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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.DateTimePicker
Friend WithEvents Timer1 As System.Windows.Forms.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.components = New System.ComponentModel.Container()
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.DateTimePicker1 = New System.Windows.Forms.DateTimePicker()
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(16, 136)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(168, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "activate"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(80, 104)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(88, 20)
Me.TextBox2.TabIndex = 2
Me.TextBox2.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(16, 72)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(64, 24)
Me.Label1.TabIndex = 3
Me.Label1.Text = "time"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(16, 104)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(64, 16)
Me.Label2.TabIndex = 4
Me.Label2.Text = "message"
'
'DateTimePicker1
'
Me.DateTimePicker1.Format =
System.Windows.Forms.DateTimePickerFormat.Time
Me.DateTimePicker1.Location = New System.Drawing.Point(80, 72)
Me.DateTimePicker1.Name = "DateTimePicker1"
Me.DateTimePicker1.ShowUpDown = True
Me.DateTimePicker1.Size = New System.Drawing.Size(88, 20)
Me.DateTimePicker1.TabIndex = 5
'
'Timer1
'
Me.Timer1.Interval = 1000
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(520, 333)
Me.Controls.AddRange(New System.Windows.Forms.Control()
{Me.DateTimePicker1, 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(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Timer1.Enabled = True

End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
If Date.Now.ToLongTimeString =
DateTimePicker1.Value.ToLongTimeString Then
MsgBox(TextBox2.Text.ToString, MsgBoxStyle.Information)
End If
End Sub
End Class
 
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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.DateTimePicker
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.components = New System.ComponentModel.Container()
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.DateTimePicker1 = New System.Windows.Forms.DateTimePicker()
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.ListBox1 = New System.Windows.Forms.ListBox()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(16, 136)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(168, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "activate"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(80, 104)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(88, 20)
Me.TextBox2.TabIndex = 2
Me.TextBox2.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(16, 72)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(64, 24)
Me.Label1.TabIndex = 3
Me.Label1.Text = "time"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(16, 104)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(64, 16)
Me.Label2.TabIndex = 4
Me.Label2.Text = "message"
'
'DateTimePicker1
'
Me.DateTimePicker1.Format =
System.Windows.Forms.DateTimePickerFormat.Time
Me.DateTimePicker1.Location = New System.Drawing.Point(80, 72)
Me.DateTimePicker1.Name = "DateTimePicker1"
Me.DateTimePicker1.ShowUpDown = True
Me.DateTimePicker1.Size = New System.Drawing.Size(88, 20)
Me.DateTimePicker1.TabIndex = 5
'
'Timer1
'
Me.Timer1.Interval = 1000
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(224, 64)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(224, 95)
Me.ListBox1.TabIndex = 6
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(520, 333)
Me.Controls.AddRange(New System.Windows.Forms.Control()
{Me.ListBox1, Me.DateTimePicker1, 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(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

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

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
For intTeller = 0 To ListBox1.Items.Count - 1
If Strings.Left(ListBox1.Items(intTeller), 8) =
Date.Now.ToLongTimeString Then
MsgBox(Strings.Right(ListBox1.Items(intTeller),
Len(ListBox1.Items(intTeller)) - 8), MsgBoxStyle.Information)
End If
Next
End Sub

Private Sub ListBox1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles ListBox1.KeyDown
If e.KeyCode = Keys.Delete Then
ListBox1.Items.Remove(ListBox1.SelectedItem)
End If
End Sub
End Class
 
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,TimeOfDay to strings and then compare?
 
Charles Watson said:
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,TimeOfDay 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
 
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.

InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'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.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

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.SuspendLayout()

'

'MainMenu1

'

Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.MenuItem1, Me.MenuItem2})

'

'MenuItem1

'

Me.MenuItem1.Index = 0

Me.MenuItem1.Text = "&File"

'

'MenuItem2

'

Me.MenuItem2.Index = 1

Me.MenuItem2.Text = "&Edit"

'

'monthBox

'

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

Me.monthBox.Name = "monthBox"

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

Me.monthBox.TabIndex = 0

Me.monthBox.Text = "Month"

'

'daysBox

'

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

Me.daysBox.Name = "daysBox"

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

Me.daysBox.TabIndex = 1

Me.daysBox.Text = "Day"

'

'yearBox

'

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

Me.yearBox.Name = "yearBox"

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

Me.yearBox.TabIndex = 2

Me.yearBox.Text = "Year"

'

'dateBoxE

'

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

Me.dateBoxE.Name = "dateBoxE"

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

Me.dateBoxE.TabIndex = 4

Me.dateBoxE.Text = "TextBox1"

'

'currentdate

'

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

Me.currentdate.Name = "currentdate"

Me.currentdate.TabIndex = 5

Me.currentdate.Text = "current date"

Me.currentdate.TextAlign = System.Drawing.ContentAlignment.MiddleCenter

'

'dateBoxC

'

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

Me.dateBoxC.Name = "dateBoxC"

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

Me.dateBoxC.TabIndex = 6

Me.dateBoxC.Text = "TextBox2"

'

'dateEntered

'

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

Me.dateEntered.Name = "dateEntered"

Me.dateEntered.TabIndex = 7

Me.dateEntered.Text = "Date entered:"

Me.dateEntered.TextAlign = System.Drawing.ContentAlignment.MiddleCenter

'

'Button1

'

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

Me.Button1.Name = "Button1"

Me.Button1.TabIndex = 8

Me.Button1.Text = "Button1"

'

'daysDiff

'

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

Me.daysDiff.Name = "daysDiff"

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

Me.daysDiff.TabIndex = 9

Me.daysDiff.Text = "date difference days"

Me.daysDiff.TextAlign = System.Drawing.ContentAlignment.MiddleCenter

'

'DateBoxD

'

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

Me.DateBoxD.Name = "DateBoxD"

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

Me.DateBoxD.TabIndex = 10

Me.DateBoxD.Text = "TextBox3"

'

'Button2

'

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

Me.Button2.Name = "Button2"

Me.Button2.TabIndex = 11

Me.Button2.Text = "Button2"

'

'monthDiff

'

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

Me.monthDiff.Name = "monthDiff"

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

Me.monthDiff.TabIndex = 12

Me.monthDiff.Text = "date difference months"

Me.monthDiff.TextAlign = System.Drawing.ContentAlignment.MiddleCenter

'

'yearDiff

'

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

Me.yearDiff.Name = "yearDiff"

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

Me.yearDiff.TabIndex = 13

Me.yearDiff.Text = "date difference years"

Me.yearDiff.TextAlign = System.Drawing.ContentAlignment.MiddleCenter

'

'dateBoxM

'

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

Me.dateBoxM.Name = "dateBoxM"

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

Me.dateBoxM.TabIndex = 14

Me.dateBoxM.Text = "TextBox4"

'

'dateBoxY

'

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

Me.dateBoxY.Name = "dateBoxY"

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

Me.dateBoxY.TabIndex = 15

Me.dateBoxY.Text = "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.TextAlign = System.Drawing.ContentAlignment.MiddleCenter

'

'mdyBox

'

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

Me.mdyBox.Name = "mdyBox"

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

Me.mdyBox.TabIndex = 17

Me.mdyBox.Text = "TextBox6"

'

'Form1

'

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

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

Me.Controls.AddRange(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(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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.Add(nDays)

Next

Dim nYear As Short

For nYear = 1 To 115

yearBox.Items.Add(nYear + 1900)

Next

End Sub

Private Sub dateBoxC_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles dateBoxC.TextChanged

dateBoxC.Text = DateString

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim eDate As String

eDate = ((1 + monthBox.SelectedIndex) & "-" & (1 + daysBox.SelectedIndex) &
"-" & _

(1901 + yearBox.SelectedIndex))

dateBoxE.Text = eDate

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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.SelectedIndex) > 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.SelectedIndex) = 2 Then

ldm = 28

ElseIf (1 + monthBox.SelectedIndex) = 4 Then

ldm = 30

ElseIf (1 + monthBox.SelectedIndex) = 6 Then

ldm = 30

ElseIf (1 + monthBox.SelectedIndex) = 9 Then

ldm = 30

ElseIf (1 + monthBox.SelectedIndex) = 11 Then

ldm = 30

Else : ldm = 31

End If

mdyBox.Text = ldmm







End Sub

End Class
 
jbw said:
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.SelectedIndex + 1900, monthBox.SelectedIndex + 1,
daysBox.SelectedIndex + 1)
diff = d.subtract(date.now)

msgbox diff.totaldays
 
Back
Top