Lab 2 Writeup

Be bossy—IT should serve you, not the other way around.

In this lab exercise, we'll look at computer software. The combination of hardware and software is what makes the computer a universal machine—so versatile that it can compute anything we can write code for. Programming is a large and significant topic, so we'll focus just on the fundamentals.

We suggest that you work in pairs (in lock-step), and, if you have any problems with anything, ask one of the other teams or one of us for pointers.

This lab requires that special software ("Peedy the Parrot") be installed on your computer. Thus, you should plan to do this one in SB 372 (our lab).

Computer Software

In this section we'll explore the concept of programming using Peedy, a simple Microsoft agent. Our Peedy application is written in Visual Basic for Applications (VBA) and runs within Microsoft Excel.

Getting Started with Peedy

To work with Peedy, do the following:

  1. Download this Excel spreadsheet: lab2-peedy.xlsm (try a right-click and "Save as"/"Save target as"), store it on your F: drive in your FIT folder, and double-click on it to fire Peedy up.
  2. When the spreadsheet opens, you will get a security warning saying warning you that Macros are disabled. The warning will appear below Excel's ribbon.
  3. If you still get a complaint about macros, you will have to configure Excel to allow macros by doing the following: This time, you'll get a security warning that allows you to "Enable Macros" as shown in step 2. Because you know where this file came from and trust its contents, you can rest reasonably assured that it's safe to enable Peedy's macros. Don't do this with a file that you don't trust! Malicious macros could do all sorts of mischief (e.g., deleting all your F: files, messing up your system configuration, etc.).
  4. If all is well, you'll get a spreadsheet that looks like this:

  5. Start the Peedy interface by pressing the red button and clicking "OK" to the ActiveX warning, and then start Peedy by pressing the "Start" button. This should give you the following:

Take some time to experiment with Peedy.

If you wear your system's headphones, you should hear Peedy "say" things to you. When you're finished, be sure to press Peedy's "stop" button before going on.

Looking Under the Hood

The Peedy agent is controlled by a program written in Visual Basic for Applications (VBA), which you can see by starting up Microsoft's VBA editor. Do this now by pressing Alt+F11. You should see the Microsoft Visual Basic programming environment. You can view the Peedy system using either of the following two views (the GUI view on the left or the VBA code view on the right):

Follow the instructions given in the image to view the VBA code that implements the SpeakIT function. Now, look through the SpeakIT code (not the whole code file, just this small part of it) and find the following things:

Taking Control

Now we'll use some simple programming to get Peedy to count to 10 on command. We could get Peedy to do this with the following set sequence of commands:

Peedy.Speak "one"
Peedy.Speak "two"
Peedy.Speak "three"
and so forth...

This would be tedious to program, and not very general. Instead, delete the VBA commands between the appropriate comments (i.e., Enter in code below here and Enter in Code above here) and then add the following code:

Speech = txtSpeak.Text
Peedy.Speak Speech
If Speech = "count to 10" Then
  For i = 1 to 10
    Peedy.Speak Cstr(i)  
  Next i
End If

The Cstr function converts the number i (i.e., 1) into the string for i (i.e., "1"). This code uses all 3 basic control constructs: If the user tells Peedy to count to 10, then repeatedly say the numbers from 1 to 10. And this is done after Peedy speaks the actual input.

You can run the Peedy GUI with your new code by choosing "Run"-"Run Sub/User Form". This compiles the code you wrote and runs it.

Try this command out now by typing "count to 10" in the Text field and pressing "SpeakIT". (Typing "count to ten" won't work. Why not? Or... if it does, why?)

Now, see if you can add similar code to respond to the command "count to 5" as well. (Hint: do not copy all of the code above, only enough to handle "count to 5".) When you're done, Peedy should be able to count to five or ten, depending on which command is entered.

Notes on Programming

Feel free to play with Peedy if there is time. Peedy is a simple, cute example of the fundamental technology that drives IT. What we've done here may be limited, but it's an illustration of the power afforded to those that learn how to program computers.

A Challenge

If you have extra time and would like to set some extra credit for this lab, try to solve either of the following challenges (without affecting any of Peedy's previous abilities):

Submitting your Work

For this lab, use KV to submit your modified version of the lab2-peedy.xlsm file. If necessary, see Lab #1 for instructions on how to do this.