CIS 220 - 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. 

  • The program will obtain the month from the user's selection out of a list box (loaded at design time) and the year from a text box. 
  • The program will then display a calendar for that month in a multi-line text box "txtOut" as shown below.
  • For the example below, assume that the user selected "March" for the month and "2006" for the 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.  Do not use the IsLeapYear function provided by VB.Net--write your own!

    • 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)

      Note that the function returns a 1 for Sunday, 2 for Monday, etc., so the leading blank days at the beginning of the month would be determined by the formula 

    Weekday(month & " " & year) - 1

    A sample  program that demonstrates the use of Weekday can be seen here.


  • 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.

  • To put the current year in the year textbox, create a Form_Load event and include a line like

    txtYear.Text = DateTime.Now.Year

Submit pseudocode or an algorithm for this program.