- Program 4
Objectives: Gain experience using control
structures, functions, and printing.
Description: This program is intended to provide you with experience using functions, select-case, if-then-else, loops, Boolean, and modulus.
Develop a program to generate the calendar for a given month and year.
Your program must account for leap years.
Your program MUST include the following functions:
IsLeapYear--Most years that are evenly divided by 4 are leap years. However, years that are evenly divided by 100 but not evenly divided by 400 are not leap years. Thus 1996 is a leap year, 1900 is not, and 2000 is. IsLeapYear should return True or False.
numDaysInMonth--Use a Select Case to determine the number of days in the month. Make the Select Case as brief as possible. This function should call isLeapYear in order to determine the number of days in February.
numberOfLeadingBlankDays--Used to determine and return the number of leading blank days at the beginning of the month. Use the Weekday function to determine the actual starting day and print the calendar accordingly. This is an example of a built-in function provided by VB. After the user specifies the month and year, simply send those values to the Weekday function. For example, if month = "January" and year = 2001, the correct function call would be:
Weekday(month & " " & year)
Weekday(month & " " & year) - 1
All code will be properly commented.
Part of the challenge of this program is determining the correct algorithm needed to format each line of the calendar correctly. You may have to change the font to courier make the columns work correctly. Why?
I recommend that you build a string to hold your calendar data, and then output the string to the text box. Why?
To force a line feed in a printed line, use the VB constant, VbCrLf.
Be sure to use a list box for input of the
month. Make it large enough to display multiple lines, and
remember that the user will have to CLICK one in order to select it.