Think i start loosing the plot here....This sort of half way work, but i think i might have been looking too much at it and now can't see the forrest for all the trees....Any idea how to improve this is welcommen
Private ReadOnly CurrentDay As Date = Today
Private Property Age As Integer = Nothing
Private Property myBirthDay As Date = Nothing
Private Property DaysToNextBirthDay As Long = 0
Private Property NewBirthDate As Date = Nothing
Friend Sub CalculateNextBirthdayAndAge(ByVal ThisBirthDate As Date)
Try
myBirthDay = ThisBirthDate
If ThisBirthDate.Month > CurrentDay.Month AndAlso ThisBirthDate.Month <= 12 Then
NewBirthDate = CDate(FormatDateTime(CDate(String.Format("{0}-{1}-{2}", CurrentDay.Year, ThisBirthDate.Month, ThisBirthDate.Day)), DateFormat.ShortDate))
DaysToNextBirthDay = (-(DateDiff("d", NewBirthDate, CurrentDay)))
ElseIf ThisBirthDate.Month < CurrentDay.Month AndAlso ThisBirthDate.Month >= 1 Then
NewBirthDate = CDate(FormatDateTime(CDate(String.Format("{0}-{1}-{2}", CurrentDay.Year + 1, ThisBirthDate.Month, ThisBirthDate.Day)), DateFormat.ShortDate))
DaysToNextBirthDay = (DateDiff("d", CurrentDay, NewBirthDate))
ElseIf ThisBirthDate.Month = CurrentDay.Month Then
If ThisBirthDate.Day > CurrentDay.Day Then
NewBirthDate = CDate(FormatDateTime(CDate(String.Format("{0}-{1}-{2}", CurrentDay.Year, ThisBirthDate.Month, ThisBirthDate.Day)), DateFormat.ShortDate))
DaysToNextBirthDay = (-(DateDiff("d", NewBirthDate, CurrentDay)))
ElseIf ThisBirthDate.Day < CurrentDay.Day Then
NewBirthDate = CDate(FormatDateTime(CDate(String.Format("{0}-{1}-{2}", CurrentDay.Year + 1, ThisBirthDate.Month, ThisBirthDate.Day)), DateFormat.ShortDate))
DaysToNextBirthDay = (DateDiff("d", CurrentDay, NewBirthDate))
Else
MessageBox.Show("Happy Birthday", "Happy Birthday", MessageBoxButtons.OK)
End If
End If
lblAge.Text = CInt(CInt(DateDiff(DateInterval.Month, myBirthDay, Today) / 12) & " år.").ToString
lblDaysToBirthDays.Text = DaysToNextBirthDay.ToString & " dage til næste fødseksdag..."
myBirthDay = Nothing
DaysToNextBirthDay = Nothing
NewBirthDate = Nothing
Age = Nothing
Catch ex As Exception
MessageBox.Show(ex.Message.ToString)
End Try
End Sub</pre>