'Begin description 'Makes significant values in selected pivot table(s) Bold or Italic. '(The program seeks labels containing "Sig." among the table's column labels 'and, if not found, among its row labels.) 'Dialog box allows to choose which levels to treat significant '(up to two different alphas) and provides additional options. ' 'SPSS script by Kirill Orlov 'Version 1, Feb 2002 'kior@comtv.ru; orlovk@ri-vita.ru 'http://ri-vita.ru/consulting/stats/ 'End Description Option Explicit Sub Main Begin Dialog UserDialog 490,154,"Mark Significance Levels in Selected Pivot Tables",.dlgfunc GroupBox 10,7,240,49,"Levels to mark as significant",.GroupBox2 CheckBox 30,28,40,14," <",.CheckBox1 CheckBox 150,28,40,14," <",.CheckBox2 CheckBox 320,63,150,14,"Apply cell colour(s)",.CheckBox4 GroupBox 270,7,210,49,"Text Style to mark with",.GroupBox1 OptionGroup .Group1 OptionButton 290,21,180,14,"Bold (then Bold Italic)",.OptionButton1 OptionButton 290,35,180,14,"Italic (then Bold Italic)",.OptionButton2 OKButton 380,83,90,21 CancelButton 380,106,90,21 CheckBox 20,63,230,14,"Replace nonsignificant with ""ns""",.CheckBox3 GroupBox 10,105,310,35,"If several ""Sig"" columns/rows in a table",.GroupBox3 OptionGroup .Group2 OptionButton 30,119,120,14,"Do all of them",.OptionButton3 OptionButton 180,119,130,14,"Ask what to do",.OptionButton4 TextBox 70,26,40,18,.Alpha1 TextBox 190,26,40,18,.Alpha2 PushButton 380,129,90,21,"Help",.PushButton1 End Dialog Dim dlg As UserDialog dlg.CheckBox1= 1 dlg.CheckBox4= 1 dlg.Alpha1= "0.05" dlg.Alpha2= "0.01" Dim objOutputItems As ISpssItems, objItem As ISpssItem, objActiveItem As Object Dim NSelected As Long, itemIndex As Long, bothLevels As Boolean, skip As Boolean, alpha As Double, textstyle As Integer, NSigs As Long Dim captText As String, title As String, info As String, makeCapt As Boolean, nonsig As Boolean Dim objColumnLabels As ISpssLabels, objLabels As ISpssLabels, objRowLabels As ISpssLabels, objDataCells As ISpssDataCells Dim colNum As Long, rowNum As Long, SigsAreIn As Integer, i As Long, i2 As Long Set objOutputItems= objSpssApp.GetDesignatedOutputDoc.Items NSelected= 0 For itemIndex= 1 To objOutputItems.Count-1 Set objItem= objOutputItems.GetItem(itemIndex) If objItem.SPSSType=SPSSPivot And objItem.Selected Then NSelected= NSelected+1 ReDim Preserve Selected(1 To NSelected) As Long Selected(NSelected)= itemIndex End If Next If NSelected=0 Then MsgBox "Select Pivot Table(s) or all Output to run this script", "Error" Exit Sub End If If Dialog(dlg)=0 Then Exit Sub End If If dlg.CheckBox1 And dlg.CheckBox2 Then If Val(dlg.Alpha1)>Val(dlg.Alpha2) Then bothLevels= True alpha= Val(dlg.Alpha1) Else MsgBox "The second alpha value must be less then the first", "Error" Exit Sub End If ElseIf dlg.CheckBox1 Then alpha= Val(dlg.Alpha1) ElseIf dlg.CheckBox2 Then alpha= Val(dlg.Alpha2) Else MsgBox "You must select at least one level to mark as significant", "Error" Exit Sub End If If dlg.Group1=0 Then textstyle= 2 Else textstyle= 1 End If If dlg.CheckBox3 Then captText= "ns = nonsignificant at the "+CStr(alpha)+" level." End If For itemIndex= 1 To NSelected Set objItem= objOutputItems.GetItem(Selected(itemIndex)) Set objActiveItem= objItem.Activate objActiveItem.UpdateScreen= False NSigs= 0 Set objColumnLabels= objActiveItem.ColumnLabelArray For colNum= 0 To objColumnLabels.NumColumns-1 For rowNum= 0 To objColumnLabels.NumRows-1 If InStr(objColumnLabels.ValueAt(rowNum,colNum),"Sig.")>0 Then NSigs= NSigs+1 ReDim Preserve SigLabelCol(1 To NSigs) As Long ReDim Preserve SigLabelRow(1 To NSigs) As Long SigLabelCol(NSigs)= colNum SigLabelRow(NSigs)= rowNum End If Next Next If NSigs>0 Then SigsAreIn= 1 Set objLabels= objActiveItem.ColumnLabelArray Else Set objRowLabels = objActiveItem.RowLabelArray For rowNum= 0 To objRowLabels.NumRows-1 For colNum= 0 To objRowLabels.NumColumns-1 If InStr(objRowLabels.ValueAt(rowNum,colNum),"Sig.")>0 Then NSigs= NSigs+1 ReDim Preserve SigLabelCol(1 To NSigs) As Long ReDim Preserve SigLabelRow(1 To NSigs) As Long SigLabelCol(NSigs)= colNum SigLabelRow(NSigs)= rowNum End If Next Next If NSigs>0 Then SigsAreIn= 2 Set objLabels= objActiveItem.RowLabelArray End If End If If NSigs>0 Then skip= False If NSigs>1 And dlg.Group2=1 Then title= "Selected Table No. "+CStr(itemIndex) info="In the current table, there are "+CStr(NSigs)+" ""Sig"" "+Choose(SigsAreIn,"columns","rows") Begin Dialog UserDialog 350,112,title,.dlg2func OKButton 250,49,90,21 Text 10,7,320,14,info,.Text1 GroupBox 20,28,210,70,"Which of them to do?",.GroupBox1 OptionGroup .Group1 OptionButton 40,49,90,14,"Do the",.OptionButton1 OptionButton 40,70,120,14,"Do all of them",.OptionButton2 TextBox 118,46,30,18,.N Text 150,49,70,14,"th of them",.Text2 PushButton 250,77,90,21,"Skip table",.PushButton1 End Dialog Dim dlg2 As UserDialog dlg2.N= "1" If Dialog(dlg2)=1 Then 'If the user pressed "Skip table" pushbutton skip= True Else If dlg2.Group1=0 And (Val(dlg2.N)<1 Or Val(dlg2.N)>NSigs) Then MsgBox "You entered incorrect value. This table will be skipped", "Error" skip= True ElseIf dlg2.Group1=0 Then SigLabelCol(1)= SigLabelCol(Val(dlg2.N)) SigLabelRow(1)= SigLabelRow(Val(dlg2.N)) ReDim Preserve SigLabelCol(1 To 1) As Long ReDim Preserve SigLabelRow(1 To 1) As Long NSigs= 1 End If End If End If If Not skip Then makeCapt= False Set objDataCells= objActiveItem.DataCellArray For i= 1 To NSigs For i2= 0 To Choose(SigsAreIn,objDataCells.NumRows,objDataCells.NumColumns)-1 rowNum= Choose(SigsAreIn,i2,SigLabelRow(i)) colNum= Choose(SigsAreIn,SigLabelCol(i),i2) If IsNumeric(objDataCells.ValueAt(rowNum,colNum)) And CStr(objDataCells.ValueAt(rowNum,colNum))<>"-1.79769313486232E+308" Then nonsig= True If bothLevels Then If objDataCells.ValueAt(rowNum,colNum)