473,671 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with the age function

21 New Member
Hi, Whenever I try and find an age function I find that it doesn't work the way I want it to... Here's what I want to do: I want the age function to first ask the user a question ("What is your date of birth?") However, no matter how I formatted it the function would not work I have tried to use "as string" and DateDiff() but nothing seems to work... If anyone can come up with a method of doing this I'd appreciate it...
kind regards,
Marren02
Oct 3 '07 #1
20 3769
Killer42
8,435 Recognized Expert Expert
Can you show us what sort of code you have tried? Your description was pretty vague. Are you having trouble with getting the date from the user, or in calculating the age, or what?

Oh, and what version of VB are you using?
Oct 3 '07 #2
Marren02
21 New Member
Can you show us what sort of code you have tried? Your description was pretty vague. Are you having trouble with getting the date from the user, or in calculating the age, or what?

Oh, and what version of VB are you using?
The version I am using is VB 6.0
I have tried examples from the web which suprisingly don't work like:

Expand|Select|Wrap|Line Numbers
  1. Public Function Age(ByVal Birthdate As System.DateTime) As Long
  2. Try
  3. Dim CurrentDate As System.DateTime = System.DateTime.Today
  4. Select Case Month(Birthdate)
  5.     Case Is < Month(System.DateTime.Today)
  6.         Age = DateDiff("YYYY", Birthdate, Now())
  7.     Case Is = Month(CurrentDate)
  8.          Select Case Day(Birthdate)
  9.              Case Is < Day(CurrentDate)
  10.                 Age = DateDiff("YYYY", Birthdate, Now())
  11.              Case Is = Day(CurrentDate)
  12.                 Age = DateDiff("YYYY", Birthdate, Now())
  13.              Case Is > Day(CurrentDate)
  14.                   Age = DateDiff("YYYY", Birthdate, Now()) - 1
  15.          End Select
  16.     Case Is > Month(CurrentDate)
  17.         Age = DateDiff("YYYY", Birthdate, Now()) - 1
  18.     Case Else
  19.         Age = 0
  20. End Select
  21. Catch ex As System.Exception
  22.     'Error handling code does here
  23. End Try
  24. End Function
which is "apparently " suppost to be code for VB 6.0 however the bits of code appear in red so i think this is someone who just likes to mess people around by saying its this version when it aint.

Basically, I just simply want to know how old the user is in years by his/her birthdate or perhaps a more complicated format with the months, days, hours, etc. In General, it's just the whole code which doesn't work I've tried editing it but with my lack of knowledge in this program it just shot angry messages at me like as if the program hates me.

I hope you manage to find a way to get round this, I have been trying to work out what is wrong but I can't seem to add in:

Datenum1 As string

Datenum1= LineIn("Please enter your date of birth in number form only")

First time I tried doing this it did not work, so I tried if commands and other functions I could find but it persisted on coming up with messages that roughly translate as "Command not recognised" "Format incorrect" "End IF,etc. needed"
"Need more ketchup...with my chips...user idiotic...can't come up with proper function..."

Eventually I gave up so now the problem is passed to you perhaps i might learn from the code which you produce if you produce any... not saying that you are not capable of doing this but it seems impossible to find a website with simple straight forward code that works... I hope these forums differ from that.
Kind regards,
marren02
Oct 3 '07 #3
debasisdas
8,127 Recognized Expert Expert
The version I am using is VB 6.0
I have tried examples from the web which suprisingly don't work like:
Before copying and pasting the code you need to understand that first.

The code you are using is not VB 6.0 code ,that is .NET code.
Oct 3 '07 #4
Marren02
21 New Member
Then why on the website I used does it say it's Visual Basic code?
http://www.codewidgets.com/product.aspx?key=24

Look under widget info it says clearly in black and white under Microsoft Access 2000/XP Visual Basic 6.0
Oct 3 '07 #5
hariharanmca
1,977 Top Contributor
then why on the website I used does it say its visual basic code?
Visual basic is common name to all versions of VB.
Just try this code.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function GetAge(ByVal Birthdate As Date) As Long
  3. On Error GoTo errExc
  4. Dim CurrentDate As Date ' System.DateTime = System.DateTime.Today
  5. CurrentDate = Format(Now, "dd/MM/yyyy")
  6. Select Case Month(Birthdate)
  7.     Case Is < Month(CurrentDate)
  8.         Age = DateDiff("YYYY", Birthdate, Now)
  9.     Case Is = Month(CurrentDate)
  10.          Select Case Day(Birthdate)
  11.              Case Is < Day(CurrentDate)
  12.                 Age = DateDiff("YYYY", Birthdate, Now)
  13.              Case Is = Day(CurrentDate)
  14.                 Age = DateDiff("YYYY", Birthdate, Now)
  15.              Case Is > Day(CurrentDate)
  16.                   Age = DateDiff("YYYY", Birthdate, Now) - 1
  17.          End Select
  18.     Case Is > Month(CurrentDate)
  19.         Age = DateDiff("YYYY", Birthdate, Now) - 1
  20.     Case Else
  21.         Age = 0
  22. End Select
  23. Exit Function
  24. errExc:
  25.     'Error handling code does here
  26. End Function
  27.  
  28.  
  29.  
which is converted to VB 6.0
Oct 3 '07 #6
Marren02
21 New Member
Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function GetAge(ByVal Birthdate As Date) As Long
  3. On Error GoTo errExc
  4. Dim CurrentDate As Date ' System.DateTime = System.DateTime.Today
  5. CurrentDate = Format(Now, "dd/MM/yyyy")
  6. Select Case Month(Birthdate)
  7.     Case Is < Month(CurrentDate)
  8.         Age = DateDiff("YYYY", Birthdate, Now)
  9.     Case Is = Month(CurrentDate)
  10.          Select Case Day(Birthdate)
  11.              Case Is < Day(CurrentDate)
  12.                 Age = DateDiff("YYYY", Birthdate, Now)
  13.              Case Is = Day(CurrentDate)
  14.                 Age = DateDiff("YYYY", Birthdate, Now)
  15.              Case Is > Day(CurrentDate)
  16.                   Age = DateDiff("YYYY", Birthdate, Now) - 1
  17.          End Select
  18.     Case Is > Month(CurrentDate)
  19.         Age = DateDiff("YYYY", Birthdate, Now) - 1
  20.     Case Else
  21.         Age = 0
  22. End Select
  23. Exit Function
  24. errExc:
  25.     'Error handling code does here
  26. End Function
  27.  
  28.  
  29.  
The code is accepted in my visual basic but when I try to run the script nothing is displayed... there must be something else you need to do with the code for it to run properly
Oct 3 '07 #7
hariharanmca
1,977 Top Contributor
Can you explain how you are calling this method?
Oct 3 '07 #8
debasisdas
8,127 Recognized Expert Expert
then why on the website I used does it say its visual basic code?
Ask that at the site from where you have copied the code.
Oct 3 '07 #9
Marren02
21 New Member
h person
----------------------------
what do you mean?

Other person
-----------------------------------
Don't think theres a way to contact this website

--------------------------------------------------------------------
I'm trying to get a code whereby the user simply enters his or her date of birth and basically it will display his or her age and may also have other things added like months, days, etc.

I'd appreciate if anyone can give me a code that works as I can't find any site with a code that will allow me to work out age with vitual basic

Kind regards,
marren02
Oct 3 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3566
by: Justin Lemkul | last post by:
Hello all, I am hoping someone out there will be able to help me. I am trying to install a program that utilizes NumPy. In installing NumPy, I realized that I was lacking Atlas. I ran into the following problems installing Atlas and NumPy, as I realized that NumPy could be installed using the Mac OSX veclib already built in. If anyone has any ideas on how to fix either of these, I would be most grateful. I am fairly new to Python...
9
2068
by: peter | last post by:
Hello all, Recently I've started to refactor my code ...(I'm using python 2.3.4) I tried to add extra functionality to old functions non-intrusively. When I used a construct, which involves renaming functions etc... I came across some recursive problems. (a basic construct can be found under the section BASIC CODE) These problems do not occur when renaming objects. (see section EXTRA CODE)
5
6072
by: Justice | last post by:
Currently I'm doing some experimenting with the XMLHTTP object in Javascript. Now, the XMLHttp object is asynchronous (at least in this case), and the following code causes a significant memory loss even though I seem to be allocaitng everything; help would be *vastly* appreciated. What am I doing wrong here? I thought I was doing everything correctly (setting things to null, for example) but none of the memory seems to get replaced. ...
2
1465
by: Jose Meireles | last post by:
Hi everyone I've created a module (in a web app) to hold several generic functions as subroutines. The problem I face is that I've got problems with the call of system functions with wich I don't have problems if creating the same function within the webform class. as an example here follows a soubroutine within a module Imports System.Web.UI
4
1721
by: stephenma7 | last post by:
Hi, everybody. I am new here. I have encountered these many problems for the last couple of days. I have Linux Fedora Core 3(Gnu G++ 3.4.2), Linux Fedora Core 2 (Gnu G++ 3.3.3), Red Hat 9 (Gnu G++ 3.2.2, this is dual processors). I have the same set of programs that I wrote and when I ran on the three machines, which have different amount of memories, processors' speeds, and settings. I got three different seg faults at different...
5
8792
by: Corky | last post by:
This works: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS INNER JOIN PROBLEMS ON PROBLEM_OBJECTS.PROBLEM_ID = PROBLEMS.PROBLEM_ID WHERE INTEGER(DAYS(CURRENT DATE) - DAYS(PROBLEMS.CLOSE_DATE)) = 365 AND PROBLEMS.CLOSE_DATE IS NOT NULL But this doesn't: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS
3
2315
by: Ryan Riehle | last post by:
Hi All! Trying to upgrade to Apache 2.0.49 and getting compile errors related to mod_auth_pgsql, any clue?: make: Entering directory `/usr/src/httpd-2.0.49' /usr/src/httpd-2.0.49/srclib/apr/libtool --silent --mode=link gcc -pthread -I/ =500 -D_BSD_SOURCE -D_SVID_SOURCE -D_GNU_SOURCE -DAP_HAVE_DESIGNATED_INITIALIZER I. -I/usr/src/httpd-2.0.49/os/unix -I/usr/src/httpd-2.0.49/server/mpm/prefork -I .49/modules/proxy
10
1867
by: Cliff | last post by:
Greetings, I have been trying to teach myself C++ over the past few weeks and have finally came across a problem I could not fix. I made a simple program that prints out a square or rectangle using the * character. The program was just for practice but I am having problems. My main problem is, in my program I use 4 functions to change or access two variables in my code. The variables are
1
1848
RMWChaos
by: RMWChaos | last post by:
I grabbed this "Rock Solid addEvent" code from this site, which is based on Mark Wubben's event-cache code. (These links for reference only.) I am having two problems with it, and the webmaster is s...l...o...w to respond. So I thought I would ask about it here. If I knew more about how this code works, I could probably figure out most of the problems myself, but with this one, I am clueless! =D First question: This may be my own...
10
1841
by: jodleren | last post by:
Hi I know, that there are a lot of people having problems with orkut.com, errors like "object expected" and named objects missing. When loading the site can generate some 10 errors, and still just leave a blue page - seems like it heavily rely on JS. Still, me and friends having problems and orkut seems just to ignore it. I am sure, that other poeple have problems, and I really wonder what
0
8472
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8909
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8667
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7428
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4221
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.