Here is the code I am using now. What I have is a datalist that pulls DateofBirth and Dead values from the database. The Dead values only equal Yes or No, but will later equal 0 or 1. I cannot seem to figure out how to do an if statement that allows the DateDiff to become a string of Deceased. Below is what I am trying to do:
Public Function Age(ByVal DOB As System.DateTime, ByVal Death As String) As Long
Dim CurrentDate As System.DateTime = System.DateTime.Today
if Death = "No" then
Select Case Month(DOB)
Case Is < Month(System.DateTime.Today)
Age = DateDiff("YYYY", DOB, Now())
Case Is = Month(CurrentDate)
Select Case Day(DOB)
Case Is < Day(CurrentDate)
Age = DateDiff("YYYY", DOB, Now())
Case Is = Day(CurrentDate)
Age = DateDiff("YYYY", DOB, Now())
Case Is > Day(CurrentDate)
Age = DateDiff("YYYY", DOB, Now()) - 1
End Select
Case Is > Month(CurrentDate)
Age = DateDiff("YYYY", DOB, Now()) - 1
Case Else
Age = 0
Age.ToString()
End Select
ElseIf Death = "Yes" then
Age = "Deceased"
Else
'What I have tried is below for the ElseIf portion and the Else portion
'(1) Age.ToString() = "Deceased or Unknown"
'(2) String.Age = "Deceased or Unknown"
'(1&2) Dim Age As String
'(3) Response.Write "Deceased or Unknown" (this works, but writes to the top of the document.)
Age = "Unknown"
End if
End Function
The errors I get are "Age is not a component of 'String', and Age is not in format of DateTime (or whatever it says), and System.FormatException: Input string was not in a correct format.
How do I get this to display the string without having to use a label, like: <asp:Label runat="server" /> and then just setting the text properties and the visible properties. I can do it that way, but would prefer not to. Any suggestions on how to convert that to a string and have it write without using a control? Thanks.