You give your date of birth and today's date. Find your age in year(s),month(s) and day(s)!
Code: Select all
//starting of programming code
# include "minigui.ch"
function main
define window age at 0,0 width 250 height 200 title "Find your age" main
define label bdaylabel
row 10
col 10
value "Your Birthday :"
end label
define datepicker bdate
row 10
col 120
value date()
end datepicker
define label todaylabel
row 40
col 10
value "Today is :"
end label
define datepicker today
row 40
col 120
value date()
end datepicker
define label age1
row 70
col 10
width 230
height 50
end label
define button find
row 120
col 100
width 60
caption "Find Age"
action findage()
end button
end window
age.center
age.activate
return nil
function findage
if age.today.value < age.bdate.value
msgstop("Today should be greater than the birthday!","Find Age")
age.age1.value := "Invalid dates"
return nil
endif
years := 0
months := 0
days := 0
years := year(age.today.value) - year(age.bdate.value)
months := month(age.today.value) - month(age.bdate.value)
if months < 0
years := years - 1
months := months + 12
endif
days := day(age.today.value) - day(age.bdate.value)
if days < 0
months := months - 1
days := days + 30
if months < 0
years := years - 1
months := months + 12
endif
endif
age.age1.value := "Age is "+str(years)+" Year(s),"+str(months)+" Month(s),"+str(days)+" Day(s)."
return nil
//end of programming code
1.Copy this code into a new age.prg file.
2. Just run "c:\hmg\batch\compile age" in a command window from the directory where the age.prg is placed.
3. You can get the executable file age.exe.
4. That's all!