•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 456,516 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,817 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 916 | Replies: 1 | Solved
![]() |
•
•
Join Date: Sep 2007
Posts: 1,058
Reputation:
Rep Power: 4
Solved Threads: 61
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:
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.
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 FunctionThe 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.
•
•
Join Date: Sep 2007
Posts: 1,058
Reputation:
Rep Power: 4
Solved Threads: 61
Nevermind, I realized what I did. I made Age a Long instead of a String so it wouldn't accept the format. This works, the code below:
Public Function Age(ByVal DOB As System.DateTime, ByVal Death As String) As String
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
Else
If Death = "Yes" then
Age = "Deceased"
Else
Age = "Unknown"
End if
End if
End Function![]() |
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- help with validating function (C++)
- int function(fstream)//illegal argument (C)
- Urgent Pascal Expert Needed (Pascal and Delphi)
- repost, function alogorithm problem (C)
- I've made some code to reject age ranges, but cant get it working (Java)
Other Threads in the ASP.NET Forum
- Previous Thread: sample message box.
- Next Thread: Datalist Repeater Help



Linear Mode