IDIS 110: Lab 9
SB 372

In this lab 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. Programming is a large and significant topic, but in this lab we'll focus on the fundamentals.

Getting Started with Peedy

To work with Peedy, do the following things:

  1. Download this Excel spreadsheet: Peedy.xls, store it on your F: drive, and double-click on it to fire Peedy up.
  2. If you get a complaint about macros, you will have to configure Excel to allow macros by clicking "OK" to the warning and then doing the following: This time, you'll get a security warning that allows you to "Enable Macros". 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.). If all is well, you'll get a spreadsheet that looks like this:

  3. 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. Try to get the bird to smile (as in the figure above), and to say things that you type in the text box. If you wear your system's headphones, you should hear Peedy "say" things to you.

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 typing Alt+F11. You should see the Microsoft Visual Student 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):

(Expand your browser screen if this is too small to read.)

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
If Speech = "count to 10" Then
   For i = 1 to 10
      Peedy.Speak Cstr(i)  
   Next i
End If

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. Notice how 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. Now, see if you can add similar code to respond to the command "Count to 5" as well (or if you've programmed before, you may be able to get him to count down from 10 to 1). Note that the Cstr function converts the number i (i.e., 1) into the string for i (i.e., "1"); as we'll see, strings and numbers have different representations.


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 simple, but it's an illustration of the power afforded to those that learn how to program computers.

Checking in: Submit your modified Peedy.xls file as an attachment to Lab #9.

The Excel Peedy code was written by Len De Rooy.
Last modified: Mon Nov 08 09:57:07 Eastern Standard Time 2004
© 2004 Calvin College