Homework 1
comp 125-609, Goldwasser
Due: 6:00pm Tuesday, September 14, 1999 (worth 5 points)
Late Option: if submitted between 6:00pm September 14 and 6:00pm September 21, you can recieve up to 3 of 5 points. No late homeworks will be accepted after 6:00pm September 21.
Purpose: To get more experience using Events, writing code using decision structures, and defining and using your own variables.
Requirements: In this assignment, we will modify the Stop Light program which we used in Lab 2. Rather than operating the light manually, we will make the stoplight run on a timer, where the interval of time for each color light is chosen by the user. Here is what is required of functionality:
  • The Form window should have three new text boxes which will allow the user to set the time interval for each of the colors individually.
  • The Form window should have a command button with caption "Start Timer". When this button is pressed, the light should start operating in timed mode, starting with the currently lit color, and the button caption should read "Stop Timer".
  • While in timed mode, if the user presses the "Stop Timer" button, the signal should stop at the current color, and the command button catption should be changed to read "Start Timer" again.
  • While in timed mode, you should disable the text boxes so that the user is not allowed to change the intervals. This is done by setting each object's "Enabled" property to False. Of course, you should re-enable them when the user stops the timer, so that the intervals can be adjusted.
  • You may assume that you have a nice user who always enters valid intervals (that is integers, greater than or equal to one). We will work on ways to enforce this in later assignments.

    A sample of a working program can be downloaded from,
    www.math.luc.edu/~mhg/comp125/homework/sampHW1.exe .


    Advice:

    For starters, you will need to use a new type of control called a Timer. This control is not discussed in the textbook. The control icon is located in the left column of the tool box and it looks like a stopwatch. For this assignment, the relative features of this object are:

  • The object has a single event type called "Timer" which is called every so often based on the current value of its "Interval" property.
  • The object has a property called "Interval" which is equal to the number of milliseconds between calls to the "Timer" event. If the Interval is set to 0 (or less), this disables the timer and there will be no events which take place.
  • You will most likely need to use If-Then-Else blocks or Select-Case blocks, as described in Section 3.1 of the text.

    You will most likely need to create and use global variables to keep track of information (such as, which is the current color displayed, is the timer currently activated).

    Here is a a useful fact for this program (and for many programs in the future). The Form has an event called "Load" which is guaranteed to be called once at the beginning of your program's execution. This is a very useful event for initializing any global variables.


    Extra Credit (1 point): Combine the functionality of both the manual light and the timed light. That is, when the timer is set to off, allow the user to go back to operating the light manually. Note, this is what is often done in a case where a police officer at an intersection can override the light and control it manually.

    Although this extra credit seems like a simple task of combining the lab and the original homework, it actually involves quite a bit more work to get correct. (certainly should be worth more than 1 point extra -- although it is not!)

    Keep in mind that when the timer is running, you do NOT want to allow the user to control the light using either clicks or the Tab button so you should disable all of the picture boxes.

    You want the two modes to interact seemlessly. That is, whichever light is left on by the manual mode should be the first light used in timer mode. Similarly, whichever light is on when the timer is turned off should remain lit as manual mode is resumed.

    A sample of a working extra credit program can be downloaded from,
    www.math.luc.edu/~mhg/comp125/homework/sampHW1extra.exe .


    To submit your homework you should,
  • Print out your project as follows. Click "File". Click "Print". In the Range box, select "Current project". In the Print What box, click on all three of "Form Image", "Code" and "Form as Text".
  • Save your project and form to a floppy disk
  • Place the printouts and the floppy disk inside a large manilla envelope. Please make sure that your name appears on the envelope as well as the disk and the printouts.