Microsoft Developer
Variables and properties exercise
Average difficulty

This Microsoft Developer VARIABLES AND PROPERTIES exercise is provided to allow potential course delegates to assess their suitability for the Wise Owl VISUAL C# 2005 WINDOWS FORMS course only, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

Exercise: Form to calculate age from date of birth

A full answer to this exercise is provided as part of the training course!

1) Create a form called frmDateOfBirth allowing someone to enter their date of birth using a DateTimePicker control:
Exercise screen-shot 1226 The author entering his date of birth
2) Attach code to the Show Age button which:
  • Creates a variable to hold the date entered (using the DateTimePicker's Value property)
  • Creates a variable to hold today's date (System.DateTime.Today will give you this)
  • Creates a variable to hold the difference between the two in days (using the DateDiff function)
  • Shows this age
3) Check that your application works:
Exercise screen-shot 1227 If only ...
4) Close down any open forms.

Thank you for showing an interest in this Visual C# 2005 Windows Forms training course! As mentioned above, full answers to this and other exercises are provided on the course. On all Wise Owl scheduled courses delegates can take away these model answers (together with their own efforts!) on a free USB stick.

All content copyright Wise Owl Business Solutions Ltd 2008.  All rights reserved..