Date: Wed, 2 Feb 2005 09:43:24 -0500
Reply-To: Manny Straehle <MStraehle@NBME.org>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Manny Straehle <MStraehle@NBME.org>
Subject: Re: output query
Content-Type: text/plain; charset="US-ASCII"
Sam
If you are familiar with scripts you can take advantage of this. If you are
not read up on it at Raynald's SPSS page.
I modified the script that was on Raynald's page to change every table in my
output to a desired decimal place (where it says EDIT #1).
Hope this helps,
Manny
' Changes Decimal Cells in all Tables of the Output.
' Written on 4/19/04 by Manny S
' File name: SetDecimals.sbs'
' # of Edits: 1'
Sub Main
Dim objPivot As PivotTable
Dim objItem As ISpssItem
Dim intDigits As Integer
Do While GetNextPivot(objPivot, objItem)
Call SetDecimalDigits(objPivot,intDigits)
SetDecimalDigits objPivot, 2 'Edit #1: change the number here
to set the number of decimal points'
Loop
End Sub
Sub SetDecimalDigits(objPivot As PivotTable, intDigits As Integer)
Dim lngRow As Long, lngCol As Long
Dim objDataCells As ISpssDataCells
Set objDataCells = objPivot.DataCellArray
With objDataCells
For lngRow = 0 To .NumRows - 1
For lngCol = 0 To .NumColumns - 1
If Not IsNull (.ValueAt (lngRow, lngCol)) Then
.HDecDigitsAt (lngRow, lngCol) = intDigits
End If
Next
Next
End With
objPivot.Autofit
End Sub
Function GetNextPivot( objPivot As PivotTable, _
objItem As ISpssItem )As Boolean
'Purpose: Find each Pivot Table in turn
'Assumptions: A Pivot Table is in the Output Doc (Navigator); output doesn't
change between calls
'Effects: each time the procedure is called, it activates the next selected
Pivot Table
'Inputs: PivotTable object, Item object that contains selected PivotTable
'Return Values: activated PivotTable, Item in the Navigator, function value
is True if a pivot table is found
Static objDocuments As ISpssDocuments ' SPSS documents.
Static objOutputDoc As ISpssOutputDoc ' Output document
Static objItems As ISpssItems ' Output Navigator items
Static intItem As Integer ' Output
Navigator item's index
Static intItemCount As Integer ' total number of
items in the navigator
Dim intItemType As Integer
Dim bolSelected As Boolean ' True if an item is
selected.
Dim bolReset As Boolean
Dim I As Integer
' initialize the return values
GetNextPivot = False
Set objPivot = Nothing
Set objItem = Nothing
' if this is the first call, set a flag to initialize things
If (objDocuments Is Nothing) Or (objOutputDoc Is Nothing) Or
(objItems Is Nothing) Then
bolReset = True
End If
If bolReset Then
'Get list of documents in SPSS.
Set objDocuments = objSpssApp.Documents
End If ' done with the document collection
If bolReset Then
' Get designated document only if there is at least one
output document.
If objDocuments.OutputDocCount > 0 Then
'Get the currently designated output document.
Set objOutputDoc = objSpssApp.GetDesignatedOutputDoc
Else
'If no navigator window exists.
MsgBox( "No navigator document found." )
Exit Function
End If
End If ' done with outputdoc
' Get the outline tree and the number of items:
If bolReset Then
Set objItems = objOutputDoc.Items
intItemCount = objItems.Count
End If
' there will be problems if anything failed, just make sure
If (objDocuments Is Nothing) Or (objOutputDoc Is Nothing) Or
(objItems Is Nothing) Then
Debug.Print "objDocuments Is Nothing: " & (objDocuments Is
Nothing)
Debug.Print "objOutputDocIs Nothing: " & (objOutputDoc Is
Nothing)
Debug.Print "objItems Is Nothing: " & (objItems Is Nothing)
MsgBox "There was a problem with the Navigator document.",
vbExclamation, "GetNextPivot"
Exit Function
End If
' a simple check that output hasn't changed
If intItemCount <> objItems.Count Then
MsgBox "Output changed while Script was running.",
vbExclamation, "GetNextPivot"
Exit Function
End If
If bolReset Then
intItem = 0
End If
' Get the next pivot table.
For I = intItem To intItemCount - 1
Set objItem = objItems.GetItem(I)
intItemType = objItem.SPSSType
If intItemType = SPSSPivot And InStr(objItem.Label,strLabel)
> 0 Then
intItem = I + 1
' start here next time
Set objPivot = objItem.ActivateTable()
'Activate the pivot table.
GetNextPivot = True ' We
did find a pivot table.
Exit For '
Exit the loop.
End If
Next I
If GetNextPivot = False And intItem = 0 Then
'No pivot table was found.
MsgBox( "There are no Pivot Tables in the output." )
Exit Function
End If
End Function
Manfred M. Straehle
Scoring Services
mstraehle@nbme.org
215-590-9873
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Sam
Williams
Sent: Wednesday, February 02, 2005 9:28 AM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: output query
**********************************************************************
Please notify the sender immediately if you have received this
email by mistake and delete it from your system
**********************************************************************
Is there a way to force output to be displayed to just two decimal places?I
can change each table manually but am sure it must be possible to do it
automatically!
Thanks in advance!
Sam
-----------------------------------------------------------------------------
-----------------------------------------------------
Centrex is the registered trademark of the Central Police Training and
Development Authority, formerly known as National Police Training (NPT).
Centrex provides training and development opportunities from 20 sites
throughout England and Wales and is a major supplier of products and services
to law enforcement organisations in over 60 countries. Visit our website at
www.centrex.police.uk
=========================DISCLAIMER=============================
Any opinions expressed in this email are those of the individual and not
necessarily those of Centrex. It is intended only for the person(s) to whom
it is addressed and may contain privileged and/or confidential information.
Accordingly, the copying, dissemination, distribution, or use of this message
to any other person may constitute a breach of Civil or Criminal Law.
=================================================================