CS 10, Spring 1998

Lab 4.4 Message and Function Handlers

The purpose of this lab is to give practice using and writing message and function handlers in HyperTalk.


Assignment for the Next Lab


Lab 4.4 Instructions

  1. Open a copy of the 'No Account' stack.

  2. Review the HyperCard object hierarchy (section 4.6, figures 4.5 and 4.7). Normally a message will be passed up the hierarchy until it can be responded to. The send command allows you to side step the normal hierarchy and to direct a message to a particular object. Look at the "By ID" button's script. It uses a "TurnOn" message; where is this message intercepted?

  3. Do lab exercise 5.2 on page 155. When you have finished, call one of use over and show us your stack.
  4. 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?

  5. Write a FormatOK function handler, as specified in lab exercise 7.2. This handler will have one parameter, which will represent the line number to check the format of, and it will return a boolean value (either true or false), depending on whether or not the format of the speified line is ok. The form of your handler is shown below:

  6. 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.

    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?

  7. 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."

  8. Demonstrate your modifications for one of the instructors.