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