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:
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):
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:
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.