User Name Password Register
DaniWeb IT Discussion Community
All
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,524 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,809 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: 917 | Replies: 1 | Solved
Reply
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Age Function Help

  #1  
Oct 1st, 2007
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Age Function Help

  #2  
Oct 3rd, 2007
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 4:13 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC