Stoplight

Getting Started

For this class, create a Visual Basic folder in your server space. You can store your programs from this class in this new folder.

Begin a new project. It should be a Windows Forms Application and you should store it in your Visual Basic folder.

Click on the form and, in the Properties box, change its Text property. I used "Stoplight Simulator".

Add a Button to the form. In the Properties box, change its Text. I used "Turn Lights On".

And a 2nd Button to the form and change its Text. I used "Simulate Stoplight".

Add a Label to the form for the red light. Change its Name to (possibly) lblRed. Change its BackColor to a dark red. Change the Font to at least 24. (This is a way of making the Label bigger. Resizing a Label doesn't work.) Change the ForeColor (the color of the text) to the same color that you used for the BackColor (this will make the text disappear).

Copy-paste your Label and paste it into the form. This will be the yellow light. Change its Name, BackColor, Font and ForeColor.

Create the green Label in the same way.

To align the 3 stoplights perfectly, you can click on 1 light and CTRL-click on the other 2. Then: Format > Align > Centers and Align > Vertical Spacing > Make Equal.

Here's how my form looks once it is set up:

 

4 points

Double-click on Button 1 to go to the Code View for the program. The code that you put here will run when the user clicks this button. What this button is supposed to do is to "turn on" all 3 lights, make them bright. Here is how you could change lblRed from dark red to bright red:
lblRed.BackColor = Color.Red

Put in similar code to "turn on" all 3 lights.

 

8 points

When this button is clicked, a stop-light is simulated: a continuous cycle of green - yellow - red. When a given light is bright, the other two lights are dark. (When you run the program, click Button 1 before clicking Button 2.) "Pseudocode" is halfway between English and code. Here is pseudocode for making this "stopight simulation" work. You will need an IF - ELSEIF - ELSEIF - ELSE statement:

if the green light is 'on' then
   turn the green light 'off'
   turn 'on' the yellow light
elseif the yellow light is on
   turn the yellow light off
   turn the red light on
elseif the red light is on
   turn the red light off
   turn the green light on
end if

If you want the form to fill the screen, try adjusting Layout > Size for the form.

Demo

You can download my version of this program here, to get an idea of what your program will do when it is complete. Right-click on the link and choose 'Save Target As' to download stoplight3.zip. Once the file is downloaded, double-click on it to unzip it. Then click on 'StopLight' (with file type 'Application') to run the program.