CS 10, Fall 1997

Lab 8: Advanced Scripting: Functions


Outline


Assignment for the Next Lab

Read pp. 170-178 and pp. 183-187.

For Tuesday's discussion, view "The World at Your Fingertips" (part 5, the last and final installment of "The Machine that Changed the World" series) and write a reaction paper.


Lab 8 Instructions

  1. Read part 7.2 of lab exercise 7 on page 165. If all the calculation and sorting scripts should be able to use the function FormatOK, where should you define it-- in a button script, in the card script, in the background script?

  2. We will work on this function as a class. Once you have a version of the function ready to test, unlock the data field and edit a few of lines so that they are missing some information. Re-lock the data field. Open the message window and test the FormatOK function on several of the data lines. For example, type FormatOk(3) into the message box and then press return. This should test whether line 3 has 4 items in it. Note that you will be testing the function on only one line at a time.

    While you're in the message box, test out the answer command as well. Try typing:

    answer "This is a test" with "OK"

    What does this command do? Look it up in the appendix. How could you use this command in combination with the function FormatOK to warn the user of faulty data?

  3. Open the "Maximum Balance" script and decide where to use the FormatOK function to determine if the data is valid before processing it. Modify the script so that it uses the function FormatOK and the answer command to tell the user which lines are missing information. For example, if line 2 has only two words in it, then after the user clicks the "Maximum Balance" button, an error message should appear saying something like "Warning-- insufficient data in line 2."

  4. Demonstrate your modifications for one of the instructors.

  5. If time permits, do lab exercise 7.1 in your book.

  6. Use any remaining time to practice scripting by doing any of the labs which you have yet to complete or by trying some of the scripting exercises on the "Summary of Put, Repeat and If" handout which I gave to you in lab last Thursday.