23 Replies - 24460 Views - Last Post: 02 July 2011 - 01:57 PM
#1
visual basic 6.0 simple age calculator
Posted 15 February 2009 - 07:46 PM
actualy i have to do the simple age calculator programme in visual basic 6.0 that allows the user to enter two different date of birth and calculate their average age!!!!!!!!!!!!!!!!!!!!!!!!!!
it's very hard for me because i'm just a beignner and i can't handle this task. if anyone code help me i would really appriciate it.
many thanks
Replies To: visual basic 6.0 simple age calculator
#2
Re: visual basic 6.0 simple age calculator
Posted 15 February 2009 - 08:11 PM
#3
Re: visual basic 6.0 simple age calculator
Posted 15 February 2009 - 10:51 PM
#4
Re: visual basic 6.0 simple age calculator
Posted 16 February 2009 - 03:11 AM
make 2 textboxes a label and a button
in form code put...
private sub button1_Click()
intYear = Year(Now) ' Current year
averageAge = ((intYear - val(textbox1.text)) + (intYear - val(textbox2.text))) / 2
label1.caption = str(averageAge) 'its not reaal pretty but the maths is clear i guess...
end sub
as a note this post contains no more info than a google search provides in the previews of site content...
This post has been edited by luigiplumbersinc: 16 February 2009 - 03:12 AM
#5
Re: visual basic 6.0 simple age calculator
Posted 17 February 2009 - 05:48 AM
bsaunders, on 15 Feb, 2009 - 07:11 PM, said:
hi dear
actualy this task is very hard to do for me but i have to . what i have so far it's very simple and itn't working
i put to textbox for date of birth of two person and named txtname1 and txtname2 and also i put cmdcalculate and txttotalaverage
in the private sub cmdcalculate_Click() i put the following code:
private sub cmdcalculate_Click()
dim txttotalaverage as integer
txttotalaverage = format((date-cdate(txtname1)) +(date-cdate(txtname2))/2
end sub
but this is not working i really confused i don't know what should i do . i would appreciate it if you could help me in this matter
best regards
#6
Re: visual basic 6.0 simple age calculator
Posted 17 February 2009 - 07:50 PM
naser123456, on 17 Feb, 2009 - 04:48 AM, said:
bsaunders, on 15 Feb, 2009 - 07:11 PM, said:
hi dear
actualy this task is very hard to do for me but i have to . what i have so far it's very simple and itn't working
i put to textbox for date of birth of two person and named txtname1 and txtname2 and also i put cmdcalculate and txttotalaverage
in the private sub cmdcalculate_Click() i put the following code:
private sub cmdcalculate_Click()
dim txttotalaverage as integer
txttotalaverage = format((date-cdate(txtname1)) +(date-cdate(txtname2))/2
end sub
but this is not working i really confused i don't know what should i do . i would appreciate it if you could help me in this matter
best regards
firstly i suppose i should tell you what they keep telling me post your code between code and /code tags you know like it says in the big yellow sqaure when your posting that has the heading "READ THIS FIRST:"
anyway whatever method you use to find the different between their birthdate and the current date as u did above
txttotalaverage = format((date-cdate(txtname1)) +(date-cdate(txtname2))/2
if that is giving you the answer you want you can find out for yourself by adding to our code an actual way of viewing the result and actually using the contents of the text boxes as the dates instead of their control ID's "txtname1.text"
private sub cmdcalculate_Click() txttotalaverage.text = str(format((date-cdate(txtname1.text)) +(date-cdate(txtname2.text))/2 end sub
however since it is a "simple" age calculator you may as well just input a year of birth into each
and use the following code
private sub cmdcalculate_Click()
' yyyy meaning the year in 4 digits e.g: 2009
'Mid(Date, 6) should take omit the days and months and just grab the end of the current date yyyy (2009)
txttotalaverage.text = Str((DateDiff("yyyy", txtname1.text, Mid(Date, 6)) + DateDiff("yyyy", txtname2.text, Mid(Date, 6))) / 2)
end sub
goodluck
This post has been edited by luigiplumbersinc: 17 February 2009 - 07:51 PM
#7
Re: visual basic 6.0 simple age calculator
Posted 18 February 2009 - 02:08 AM
private sub cmdcalculate_click()
if IsDate(Txt3.Text) then
Txt3.Text = Format(Txt3.text, "dd/mm/yyyy")
Else
MsgBox ("Wrong Date"), vbCritical
Elseif IsDate(Txt3.Text) then
Txt3.Text = Format(Txt3.text, "dd/mm/yyyy")
Else
MsgBox ("Wrong Date"), vbCritical
End If
bt it's not working ?!!!!!!!!!!!!!
best regards
naser123456, on 18 Feb, 2009 - 01:06 AM, said:
private sub cmdcalculate_click()
if IsDate(Txt3.Text) then
Txt3.Text = Format(Txt3.text, "dd/mm/yyyy")
Else
MsgBox ("Wrong Date"), vbCritical
Elseif IsDate(Txt4.Text) then
Txt4.Text = Format(Txt4.text, "dd/mm/yyyy")
Else
MsgBox ("Wrong Date"), vbCritical
End If
bt it's not working ?!!!!!!!!!!!!!
best regards
#8
Re: visual basic 6.0 simple age calculator
Posted 18 February 2009 - 02:19 AM
private sub cmdcalculate_click()
if IsDate(Txt3.Text) then
Txt3.Text = Format(Txt3.text, "dd/mm/yyyy")
Else
MsgBox ("Wrong Date"), vbCritical
End If
if your IsDate isnt working properly then you can try a custom version to determine whether its a date yourself
If Len(Txt3.Text) = 10 Then
If IsNumeric(Mid(Txt3.Text, 1, 2)) And IsNumeric(Mid(Txt3.Text, 4, 2)) And IsNumeric(Mid(Txt3.Text, 7)) Then
Txt3.Text = Format(Txt3.Text, "dd/mm/yyyy")
Else
MsgBox ("Invalid Date!, non-numeric input"), vbCritical
End If
Else
MsgBox ("Invlid Date!, date length incorrect please format dd/mm/yyyy"), vbCritical
End If
hope it helps, Goodluck
This post has been edited by luigiplumbersinc: 18 February 2009 - 02:21 AM
#9
Re: visual basic 6.0 simple age calculator
Posted 18 February 2009 - 07:41 AM
thank you very mach you are a really helpful person thank you very mach . but the code you have sent me earlier is not workind ?!
#10
Re: visual basic 6.0 simple age calculator
Posted 18 February 2009 - 04:46 PM
naser123456, on 18 Feb, 2009 - 06:41 AM, said:
thank you very mach you are a really helpful person thank you very mach . but the code you have sent me earlier is not workind ?!
well i have never used the format function... and i dont own VB to test the code... what error are you having?
#11
Re: visual basic 6.0 simple age calculator
Posted 18 February 2009 - 08:09 PM
#12
Re: visual basic 6.0 simple age calculator
Posted 18 February 2009 - 10:40 PM
#13
Re: visual basic 6.0 simple age calculator
Posted 19 February 2009 - 12:01 PM
i hope you are alright.
this is my project entire code :
Private Sub cmdCalculate_Click()
lblAverage.ForeColor = vbBlue
lblresult.ForeColor = vbBlue
If Len(Txt3.Text) = 10 Then
If IsNumeric(Mid(Txt3.Text, 1, 2)) And IsNumeric(Mid(Txt3.Text, 4, 2)) And IsNumeric(Mid(Txt3.Text, 7)) Then
Txt3.Text = Format(Txt3.Text, "dd/mm/yyyy")
Else
MsgBox ("Invalid Date!, non-numeric input"), vbCritical
End If
Else
MsgBox ("Invlid Date!, date length incorrect please format dd/mm/yyyy"), vbCritical
End If
If txtname1.Text = "" Or txtname2.Text = "" Or Txt3.Text = "" Or Txt4.Text = "" Then
MsgBox "Please complete all the fields", vbExclamation + vbOKOnly, "Error Message"
Else
c = (txtname1.Text)
d = (txtname2.Text)
adate = Txt4.Text
bdate = Txt3.Text
curdate = Now
lblresult.Caption = Format(DateDiff("yyyy", bdate, curdate) + DateDiff("yyyy", adate, curdate)) / 2 & Space(1) & "years"
lblAverage = c & Space(1) & "and" & Space(1) & d & Space(1) & " have an average age of"
End If
End Sub
Private Sub cmdClear_Click()
txtname1.Text = ""
txtname2.Text = ""
Txt3.Text = ""
Txt4.Text = ""
lblresult.Caption = ""
lblAverage.Caption = ""
End Sub
Private Sub cmdExit_Click()
Response = MsgBox("Exit The Project?", vbInformation + vbYesNo, "Are you sure?")
If Response = vbYes Then
Unload Me
ElseIf Response = vbNo Then
Me.Refresh
End If
End Sub
Private Sub Form_Load()
Dim c As String
Dim d As String
Dim e As String
Dim curdate As Date
Dim bdate As Date
Dim adate As Date
End Sub
thank you very mach
#14
Re: visual basic 6.0 simple age calculator
Posted 19 February 2009 - 08:05 PM
the only problem you need to fix is that you only used the code i sent you to determine whether the text box contains a date for Txt3 and not Txt4
please open the attatchment
Attached image(s)
#15
Re: visual basic 6.0 simple age calculator
Posted 20 February 2009 - 04:45 AM
best regards
good luck
|
|

New Topic/Question
Reply




MultiQuote



|