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
20 3769
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?
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: - Public Function Age(ByVal Birthdate As System.DateTime) As Long
-
Try
-
Dim CurrentDate As System.DateTime = System.DateTime.Today
-
Select Case Month(Birthdate)
-
Case Is < Month(System.DateTime.Today)
-
Age = DateDiff("YYYY", Birthdate, Now())
-
Case Is = Month(CurrentDate)
-
Select Case Day(Birthdate)
-
Case Is < Day(CurrentDate)
-
Age = DateDiff("YYYY", Birthdate, Now())
-
Case Is = Day(CurrentDate)
-
Age = DateDiff("YYYY", Birthdate, Now())
-
Case Is > Day(CurrentDate)
-
Age = DateDiff("YYYY", Birthdate, Now()) - 1
-
End Select
-
Case Is > Month(CurrentDate)
-
Age = DateDiff("YYYY", Birthdate, Now()) - 1
-
Case Else
-
Age = 0
-
End Select
-
Catch ex As System.Exception
-
'Error handling code does here
-
End Try
-
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
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.
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. -
-
Public Function GetAge(ByVal Birthdate As Date) As Long
-
On Error GoTo errExc
-
Dim CurrentDate As Date ' System.DateTime = System.DateTime.Today
-
CurrentDate = Format(Now, "dd/MM/yyyy")
-
Select Case Month(Birthdate)
-
Case Is < Month(CurrentDate)
-
Age = DateDiff("YYYY", Birthdate, Now)
-
Case Is = Month(CurrentDate)
-
Select Case Day(Birthdate)
-
Case Is < Day(CurrentDate)
-
Age = DateDiff("YYYY", Birthdate, Now)
-
Case Is = Day(CurrentDate)
-
Age = DateDiff("YYYY", Birthdate, Now)
-
Case Is > Day(CurrentDate)
-
Age = DateDiff("YYYY", Birthdate, Now) - 1
-
End Select
-
Case Is > Month(CurrentDate)
-
Age = DateDiff("YYYY", Birthdate, Now) - 1
-
Case Else
-
Age = 0
-
End Select
-
Exit Function
-
errExc:
-
'Error handling code does here
-
End Function
-
-
-
which is converted to VB 6.0
-
-
Public Function GetAge(ByVal Birthdate As Date) As Long
-
On Error GoTo errExc
-
Dim CurrentDate As Date ' System.DateTime = System.DateTime.Today
-
CurrentDate = Format(Now, "dd/MM/yyyy")
-
Select Case Month(Birthdate)
-
Case Is < Month(CurrentDate)
-
Age = DateDiff("YYYY", Birthdate, Now)
-
Case Is = Month(CurrentDate)
-
Select Case Day(Birthdate)
-
Case Is < Day(CurrentDate)
-
Age = DateDiff("YYYY", Birthdate, Now)
-
Case Is = Day(CurrentDate)
-
Age = DateDiff("YYYY", Birthdate, Now)
-
Case Is > Day(CurrentDate)
-
Age = DateDiff("YYYY", Birthdate, Now) - 1
-
End Select
-
Case Is > Month(CurrentDate)
-
Age = DateDiff("YYYY", Birthdate, Now) - 1
-
Case Else
-
Age = 0
-
End Select
-
Exit Function
-
errExc:
-
'Error handling code does here
-
End Function
-
-
-
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
Can you explain how you are calling this method?
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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)
|
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. ...
|
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
|
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...
| |
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
|
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
|
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
|
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...
|
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
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |