Language Guide
CHAPTER 8
Handlers
Using Subroutines 223
Types of Subroutines 8
There are two types of subroutines: those with labeled parameters and those
with positional parameters.
■ Labeled parameters are identified by their labels and can be listed in any
order. Subroutines with labeled parameters can also have a direct parameter.
The direct parameter, if present, must be listed first.
■ Positional parameters must be listed in a specific order, which is defined in
the subroutine definition.
For example, the following statement calls a subroutine with positional
parameters.
minimumValue(150, 4000)
The following statement calls a subroutine with labeled parameters. The direct
parameter is the list of filenames. The labeled parameters are identified by the
labels stringToFind and checkCase.
findFiles of {"March Expenses", "April Expenses",
"May Expenses", "June Expenses"} given
stringToFind:"LeChateau", checkCase:false
The definition for a subroutine determines what kind of parameters the
subroutine requires. When you call a subroutine, you must list its parameters
in the same way they are specified in the subroutine definition.
You can also have subroutines with no parameters. To indicate that a subroutine
has no parameters, you must include a pair of empty parentheses after the
subroutine name in both the subroutine definition and the subroutine call. For
example, the following script shows the definition and subroutine call for a
subroutine called helloWorld that has no parameters.
on helloWorld()
display dialog "Hello World"
end
helloWorld()