Database Reference
In-Depth Information
UP TO SPEED: THE RIGHT WAY TO CREATE SUBSCRIPTS
When you think about ways to break your script into smaller pieces, you should be thinking about
tasks. It makes good sense to create a smaller script to do one of the tasks needed in the larger script.
It doesn't make sense to simply take a long script and break it in two, so that the last step in the first
script simply performs the second script. Breaking scripts up that way has all the disadvantages of
multiple scripts (more windows to work in, more scripts to scroll through) and none of the advant-
ages (neither script is particularly simple or self-contained, and neither can be run individually for
testing purposes). Also, as you look for places to use subscripts, look for opportunities for reuse. In
other words, look for things the script has to do more than once in two different places. It almost al-
ways makes sense to use a subscript in this situation.
In most cases, the right way to subdivide a script is to create one master script that starts and fin-
ishes the process. The “Create Invoice for Job” script does that. It starts by finding unbilled line
items and finishes by showing the invoice. Along the way, it relies on other simple scripts to get the
whole job done.
There's no problem with a subscript having subscripts of its own. In fact, subscripts often do. But
you should structure the entire set of scripts so that the top-level script implements the highest-level
logic and behavior of the entire script itself. Each subscript should, in turn, do some particular task
from start to finish. If the task is particularly complex, then the subscript itself might implement
only its highest level of logic, calling on more subscripts to handle parts of the task. Since you're in
the habit of naming scripts descriptively, each subscript's name can provide nearly as much informa-
tion as a comment. When you complete the “Create Invoice for Job” script, even though it's some-
what complex, you can easily follow its structure. The script almost reads like a topic, describing
exactly what it's doing.
Now create the comments for the Create Invoice Record subscript. Here are the comments to
help you remember the process when it's time to flesh this script out:
▪ TODO: Switch to the Invoice layout.
▪ TODO: Create a new invoice record that's related to the current Job.
▪ TODO: Return to the original layout.
▪ TODO: Send script results to the parent script.
The Process Expenses and Process Timeslips scripts are almost exactly the same. The con-
text is different, because the data is in different tables and the data each script moves is dif-
ferent. But the process you'll use to find and process totals is very similar, so your comments
notes can be the same for now. You'll create the custom pieces for each script in later exer-
cises. Create those two subscripts shown now. Here are the comments you need to write for
the Process Timeslips subscript:
Search WWH ::




Custom Search