User Guide
637
SPSS Scripting
Facility
to get a pivot table object, you have to first get the output document that contains the
pivot table and then get the items in that output document.
Each object t
hat you get is stored in a variable. (Remember that all you are really
storing in the variable is a reference to the object.) One of the first steps in creating a
script is often to declare variables for the objects that you need.
Tip:Itisdi
fficult to understand how scripts work if you do not understand how
the program works. Before writing a script, use the mouse to perform the task
several times as you normally would. At each step, consider what objects you are
manipulat
ing and what properties of each object you are changing.
Variable Declarations (Scripting)
Although not always required, it is a good idea to declare all variables before using
them. This
is most often done using Dim declaration statements:
Dim objOut
putDoc As ISpssOutputDoc
Dim objPivotTable A s PivotTable
Dim intType As Integer
Dim strLab
el As String
Each declaration specifies the variable name and type. For example, the first
declaration above creates an object variable named objOutputDoc and assigns this
variable t
othe
ISpssOutputDoc object class. The variable does not yet have a value
because it has not been set to a particular output document. All the statement does
is declare that the variable exists. (This process has been referred to as “renaming
the objec
ts you want to use.”)
Varia b le naming conventions. By convention, the name of each variable indicates
its type. Object variable names begin with obj, integer variables begin with int,
and strin
g variables begin with
str. These are only conventions—you can name
your variables anything you want—but following them makes it much easier to
understand your code.
SPSS obj
ect classes.
ISpssOutputDoc and PivotTable are names of SPSS object
classes. Each class represents a type of object that the program can create, such as
an output document or pivot table. Each object class has specific properties and