Compatibility with Versions Prior to 16.0
Obsolete Methods and Properties
A number of automation methods and properties are obsolete for version 16.0 and above. In terms of general features, this includes all objects associated with interactive graphs, the Draft Document object, and methods and properties associated with maps. For additional information, see "Release Notes for Version 16.0" in the help system provided with the IBM® SPSS® Statistics Basic Script Editor. The IBM SPSS Statistics-specific help is accessed from Help>IBM SPSS Statistics Objects Help, in the script editor.
Global Procedures
Prior to version 16.0, the scripting facility included a global procedures file. For version 16.0 and above the scripting facility does not use a global procedures file, although the pre-16.0 version of Global.sbs (renamed Global.wwd) is installed for backwards compatibility.
To migrate a pre-16.0 version of a script that called functions
in the global procedures file, add the statement '#Uses "<install dir>\Samples\Global.wwd"
to the
declarations section of the script, where <install dir>
is the directory where IBM SPSS Statistics is installed. '#Uses
is a special comment recognized by the Basic script
processor. If you're not sure if a script uses the global procedures
file, you should add the '#Uses
statement. You can also use '$Include:
instead of '#Uses
.
Legacy Autoscripts
Prior to version 16.0, the scripting facility included a single autoscript file containing all autoscripts. For version 16.0 and above there is no single autoscript file. Each autoscript is now stored in a separate file and can be applied to one or more output items, in contrast to pre-16.0 versions where each autoscript was specific to a particular output item.
Some of the autoscripts installed with pre-16.0 versions are available as a set of separate script files located in the Samples subdirectory of the directory where IBM SPSS Statistics is installed. They are identified by a filename ending in Autoscript, with a file type of wwd. By default, they are not associated with any output items. The association is done from the Scripts tab of the Options dialog. See the topic Script options for more information.
Any custom autoscripts used in pre-16.0 versions must be manually converted and associated with one or more output items, from the Scripts tab of the Options dialog. The conversion process involves the following steps:
- Extract the subroutine specifying the autoscript from the legacy Autoscript.sbs file and save it as a new file with an extension of wwd or sbs. The name of the file is arbitrary.
- Change the name of
the subroutine to
Main
and remove the parameter specification, keeping track of which parameters are required by the script, such as a pivot table that triggers the autoscript. - Use the
scriptContext
object (always available) to get the values required by the autoscript, such as the output item that triggered the autoscript. - From the Scripts tab of the Options dialog, associate the script file with the output object.
To illustrate the converted code, consider the autoscript Descriptives_Table_DescriptiveStatistics_Create from the legacy Autoscript.sbs file.
Sub Descriptives_Table_DescriptiveStatistics_Create _
(objPivotTable As Object,objOutputDoc As Object,lngIndex As Long)
'Autoscript
'Trigger Event: DescriptiveStatistics Table Creation after running
' Descriptives procedure.
'Purpose: Swaps the Rows and Columns in the currently active pivot table.
'Assumptions: Selected Pivot Table is already activated.
'Effects: Swaps the Rows and Columns in the output
'Inputs: Pivot Table, OutputDoc, Item Index
Dim objPivotManager As ISpssPivotMgr
Set objPivotManager=objPivotTable.PivotManager
objPivotManager.TransposeRowsWithColumns
End Sub
Following is the converted script:
Sub Main
'Purpose: Swaps the Rows and Columns in the currently active pivot table.
'Effects: Swaps the Rows and Columns in the output
Dim objOutputItem As ISpssItem
Dim objPivotTable as PivotTable
Set objOutputItem = scriptContext.GetOutputItem()
Set objPivotTable = objOutputItem.ActivateTable
Dim objPivotManager As ISpssPivotMgr
Set objPivotManager = objPivotTable.PivotManager
objPivotManager.TransposeRowsWithColumns
objOutputItem.Deactivate
End Sub
- Notice that nothing in the converted script indicates which object the script is to be applied to. The association between an output item and an autoscript is set from the Scripts tab of the Options dialog and maintained across sessions.
-
scriptContext.GetOutputItem
gets the output item (anISpssItem
object) that triggered the autoscript. - The
object returned by
scriptContext.GetOutputItem
is not activated. If your script requires an activated object, you'll need to activate it, as done in this example with theActivateTable
method. When you're finished with any table manipulations, call theDeactivate
method.
For version 16.0, there is no distinction between scripts that are run as autoscripts and scripts that aren't run as autoscripts. Any script, appropriately coded, can be used in either context. See the topic The scriptContext Object for more information.
Note: To trigger a script from the application creation event, see Startup Scripts.
Script Editor
For version 16.0 and above the script editor for Basic no longer supports the following pre-16.0 features:
- The Script, Analyze, Graph, Utilities, and Add-Ons menus.
- The ability to paste command syntax into a script window.
The IBM SPSS Statistics Basic Script Editor is a standalone application that is launched from within IBM SPSS Statistics via File>New>Script, File>Open>Script, or Utilities>Create/Edit AutoScript (from a Viewer window). It allows you to run scripts against the instance of IBM SPSS Statistics from which it was launched. Once opened, the editor will remain open after exiting IBM SPSS Statistics, but scripts that use IBM SPSS Statistics objects will no longer run.
File Types
For version 16.0 and above, the scripting facility will continue to support running and editing scripts with a file type of sbs. By default, new Basic scripts created with the IBM SPSS Statistics Basic Script Editor have a file type of wwd.
Using External COM Clients
For version 16.0 and above, the program identifier for instantiating IBM SPSS Statistics from an external COM client is SPSS.Application16
. Application objects
should be declared as spsswinLib.Application16. For example:
Dim objSpssApp As spsswinLib.Application16
Set objSpssApp=CreateObject("SPSS.Application16")
To connect to a running instance of the IBM SPSS Statistics client from an external COM client, use:
Dim objSpssApp As spsswinLib.Application16
Set objSpssApp=GetObject("","SPSS.Application16")
If more than one client is running, GetObject
will connect to the most recently
launched one.
Note: For post-16.0 versions, the identifier is still Application16
.