Adds the UI/dialogs to ask the data source from the user.

This commit is contained in:
依瑪貓 2016-09-07 17:21:15 +08:00
parent baa4275099
commit 4816c5250d
6 changed files with 1081 additions and 78 deletions

232
_0Main.vb
View File

@ -6,18 +6,45 @@ Option Explicit
' subMain: The main program ' subMain: The main program
Sub subMain Sub subMain
BasicLibraries.loadLibrary "XrayTool" BasicLibraries.loadLibrary "XrayTool"
Dim dStart As Date
dStart = Now
'MsgBox InStr (1, "abca", "ad") subRunCorrelation
'Xray ThisComponent.getSheets.getByIndex (0).getCellByPosition (0, 0) 'subRunPairedTTest
'subRunIndependentTTest
'subRunAnova
'subRunChi2GoodnessOfFit
'subTestCorrelation 'subTestCorrelation
subTestChi2GoodnessOfFit 'subTestPairedTTest
'subTestIndependentTTest
'subTestANOVA
'subTestChi2GoodnessOfFit
MsgBox "Done. " & Format (Now - dStart, "mm:ss") & " elapsed."
End Sub End Sub
' fnQueryFormat: Returns the index of the number format, and creates the number format if required. ' fnCheckRangeName: Checks the range name and returns the range when
' found, or null when not found.
Function fnCheckRangeName (oDoc As Object, sRangeName As String) As Object
On Error Goto ErrorHandler
Dim oController As Object, oSheet As Object
Dim nPos As Integer, sSheetName As String, oRange As Object
oController = oDoc.getCurrentController
nPos = InStr (sRangeName, ".")
If nPos = 0 Then
oSheet = oController.getActiveSheet
Else
sSheetName = Left (sRangeName, nPos - 1)
If Left (sSheetName, 1) = "$" Then
sSheetName = Right (sSheetName, Len (sSheetName) - 1)
End If
oSheet = oDoc.getSheets.getByName (sSheetName)
End If
fnCheckRangeName = oSheet.getCellRangeByName (sRangeName)
ErrorHandler:
End Function
' fnQueryFormat: Returns the index of the number format, and creates
' the number format if required.
Function fnQueryFormat (oDoc As Object, sFormat As String) As Integer Function fnQueryFormat (oDoc As Object, sFormat As String) As Integer
Dim oFormats As Object, nIndex As Integer Dim oFormats As Object, nIndex As Integer
Dim aLocale As New com.sun.star.lang.Locale Dim aLocale As New com.sun.star.lang.Locale
@ -58,17 +85,202 @@ End Function
' fnFindStatsTestDocument: Finds the statistics test document. ' fnFindStatsTestDocument: Finds the statistics test document.
Function fnFindStatsTestDocument As Object Function fnFindStatsTestDocument As Object
Dim oEnum As Object, oDoc As Object Dim oEnum As Object, oDoc As Object, sFile As String
sFile = "/statstest.ods"
oEnum = StarDesktop.getComponents.createEnumeration oEnum = StarDesktop.getComponents.createEnumeration
Do While oEnum.hasMoreElements Do While oEnum.hasMoreElements
oDoc = oEnum.nextElement oDoc = oEnum.nextElement
If oDoc.supportsService ("com.sun.star.document.OfficeDocument") Then If oDoc.supportsService ("com.sun.star.document.OfficeDocument") Then
If Right (oDoc.getLocation, Len ("/statstest.ods")) = "/statstest.ods" Then If Right (oDoc.getLocation, Len (sFile)) = sFile Then
fnFindStatsTestDocument = oDoc fnFindStatsTestDocument = oDoc
Exit Function Exit Function
End If End If
End If End If
Loop Loop
fnFindStatsTestDocument = Null End Function
' fnAskDataRange: Asks the user for the data range, or null when
' the user cancelled
Function fnAskDataRange (oDoc As Object) As Object
Dim oRange As Object, sPrompt As String, sCellsData As String
oRange = fnFindActiveDataRange (oDoc)
If IsNull (oRange) Then
sCellsData = ""
Else
sCellsData = oRange.getPropertyValue ("AbsoluteName")
End If
sPrompt = "Cells with the data:"
' Loop until we get good answer
Do While sPrompt <> ""
sCellsData = InputBox (sPrompt, "Step 1/2: Select the data range", sCellsData)
' Cancelled
If sCellsData = "" Then
Exit Function
End If
oRange = fnCheckRangeName (oDoc, sCellsData)
If IsNull (oRange) Then
sPrompt = "The range """ & sCellsData & """ does not exist."
Else
If oRange.getRows.getCount < 2 Or oRange.getColumns.getCount < 2 Then
sPrompt = "The range """ & sCellsData & """ is too small (at least 2×2)."
Else
sPrompt = ""
oDoc.getCurrentController.select (oRange)
fnAskDataRange = oRange
Exit Function
End If
End If
Loop
End Function
' fnAskDataRange2: Asks the user for the data range, or null when
' the user cancelled
Function fnAskDataRange2 (oDoc As Object) As Object
Dim oRange As Object
Dim oDialogModel As Object, oDialog As Object, nResult As Integer
Dim oTextModel As Object, oEditModel As Object
Dim oButtonModel As Object
Dim sPrompt As String, sCellsData As String
oRange = fnFindActiveDataRange (oDoc)
If IsNull (oRange) Then
sCellsData = ""
Else
sCellsData = oRange.getPropertyValue ("AbsoluteName")
End If
sPrompt = "Cells with the data:"
' Loop until we finds good data
Do While sPrompt <> ""
' Creates a dialog
oDialogModel = CreateUnoService ( _
"com.sun.star.awt.UnoControlDialogModel")
oDialogModel.setPropertyValue ("PositionX", 200)
oDialogModel.setPropertyValue ("PositionY", 200)
oDialogModel.setPropertyValue ("Height", 65)
oDialogModel.setPropertyValue ("Width", 95)
oDialogModel.setPropertyValue ("Title", "Step 1/2: Select the data range")
' Adds the prompt.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 5)
oTextModel.setPropertyValue ("PositionY", 5)
oTextModel.setPropertyValue ("Height", 15)
oTextModel.setPropertyValue ("Width", 85)
oTextModel.setPropertyValue ("Label", sPrompt)
oTextModel.setPropertyValue ("MultiLine", True)
oTextModel.setPropertyValue ("TabIndex", 1)
oDialogModel.insertByName ("txtPrompt", oTextModel)
' Adds the text input.
oEditModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlEditModel")
oEditModel.setPropertyValue ("PositionX", 5)
oEditModel.setPropertyValue ("PositionY", 25)
oEditModel.setPropertyValue ("Height", 15)
oEditModel.setPropertyValue ("Width", 85)
oEditModel.setPropertyValue ("Text", sCellsData)
oDialogModel.insertByName ("edtCellsData", oEditModel)
' Adds the buttons.
oButtonModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlButtonModel")
oButtonModel.setPropertyValue ("PositionX", 5)
oButtonModel.setPropertyValue ("PositionY", 45)
oButtonModel.setPropertyValue ("Height", 15)
oButtonModel.setPropertyValue ("Width", 40)
oButtonModel.setPropertyValue ("PushButtonType", _
com.sun.star.awt.PushButtonType.CANCEL)
oDialogModel.insertByName ("btnClose", oButtonModel)
oButtonModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlButtonModel")
oButtonModel.setPropertyValue ("PositionX", 50)
oButtonModel.setPropertyValue ("PositionY", 45)
oButtonModel.setPropertyValue ("Height", 15)
oButtonModel.setPropertyValue ("Width", 40)
oButtonModel.setPropertyValue ("PushButtonType", _
com.sun.star.awt.PushButtonType.OK)
oDialogModel.insertByName ("btnOK", oButtonModel)
' Adds the dialog model to the control and runs it.
oDialog = CreateUnoService ("com.sun.star.awt.UnoControlDialog")
oDialog.setModel (oDialogModel)
oDialog.setVisible (True)
nResult = oDialog.execute
oDialog.dispose
' Cancelled
If nResult = 0 Then
Exit Function
End If
sCellsData = oEditModel.getPropertyValue ("Text")
If sCellsData = "" Then
sPrompt = "Cells with the data:"
Else
oRange = fnCheckRangeName (oDoc, sCellsData)
If IsNull (oRange) Then
sPrompt = "The range """ & sCellsData & """ does not exist."
Else
If oRange.getRows.getCount < 2 Or oRange.getColumns.getCount < 2 Then
sPrompt = "The range """ & sCellsData & """ is too small (at least 2×2)."
Else
sPrompt = ""
oDoc.getCurrentController.select (oRange)
fnAskDataRange = oRange
Exit Function
End If
End If
End If
Loop
End Function
' fnFindActiveDataRange: Finds the selected data range.
Function fnFindActiveDataRange (oDoc)
Dim oSelection As Object, nI As Integer
Dim oRanges As Object, oRange As Object
Dim aCellAddress As New com.sun.star.table.CellAddress
Dim aRangeAddress As New com.sun.star.table.CellRangeAddress
oSelection = oDoc.getCurrentSelection
' Some data ranges are already selected.
If Not oSelection.supportsService ("com.sun.star.sheet.SheetCell") Then
' Takes the first selection in multiple selections
If oSelection.supportsService ("com.sun.star.sheet.SheetCellRanges") Then
fnFindActiveDataRange = oSelection.getByIndex (0)
' The only selection
Else
fnFindActiveDataRange = oSelection
End If
Exit Function
End If
' Finds the data range containing the single active cell
aCellAddress = oSelection.getCellAddress
oRanges = oSelection.getSpreadsheet.queryContentCells ( _
com.sun.star.sheet.CellFlags.VALUE _
+ com.sun.star.sheet.CellFlags.DATETIME _
+ com.sun.star.sheet.CellFlags.STRING _
+ com.sun.star.sheet.CellFlags.FORMULA)
For nI = 0 To oRanges.getCount - 1
oRange = oRanges.getByIndex (nI)
aRangeAddress = oRange.getRangeAddress
If aRangeAddress.StartRow <= aCellAddress.Row _
And aRangeAddress.EndRow >= aCellAddress.Row _
And aRangeAddress.StartColumn <= aCellAddress.Column _
And aRangeAddress.EndColumn >= aCellAddress.Column Then
oDoc.getCurrentController.select (oRange)
fnFindActiveDataRange = oRange
Exit Function
End If
Next nI
' Not in a data cell range
End Function End Function

View File

@ -3,13 +3,167 @@
Option Explicit Option Explicit
' subRunCorrelation: Runs the Pearsons correlation coefficient.
Sub subRunCorrelation As Object
Dim oRange As Object
Dim mLabels () As String, nI As Integer, mSelected (0) As Integer
Dim oDialogModel As Object, oDialog As Object, nResult As Integer
Dim oTextModel As Object, oListModel1 As Object, oListModel2 As Object
Dim oButtonModel As Object
Dim nColumn As Integer, oRange1 As Object, oRange2 As Object
Dim oSheets As Object, sSheetName As String, sExisted As String
Dim oSheet As Object
' Asks the user for the data range
oRange = fnAskDataRange (ThisComponent)
If IsNull (oRange) Then
Exit Sub
End If
ReDim mLabels (oRange.getColumns.getCount - 1) As String
For nI = 0 To oRange.getColumns.getCount - 1
mLabels (nI) = oRange.getCellByPosition (nI, 0).getString
Next nI
' Creates a dialog
oDialogModel = CreateUnoService ( _
"com.sun.star.awt.UnoControlDialogModel")
oDialogModel.setPropertyValue ("PositionX", 200)
oDialogModel.setPropertyValue ("PositionY", 200)
oDialogModel.setPropertyValue ("Height", 80)
oDialogModel.setPropertyValue ("Width", 95)
oDialogModel.setPropertyValue ("Title", "Step 2/2: Specify the data")
' Adds the prompt.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 5)
oTextModel.setPropertyValue ("PositionY", 5)
oTextModel.setPropertyValue ("Height", 10)
oTextModel.setPropertyValue ("Width", 85)
oTextModel.setPropertyValue ("Label", "First score column:")
oTextModel.setPropertyValue ("MultiLine", True)
oTextModel.setPropertyValue ("TabIndex", 1)
oDialogModel.insertByName ("txtPromptGroup", oTextModel)
' Adds the drop down list
oListModel1 = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlListBoxModel")
oListModel1.setPropertyValue ("PositionX", 5)
oListModel1.setPropertyValue ("PositionY", 15)
oListModel1.setPropertyValue ("Height", 10)
oListModel1.setPropertyValue ("Width", 85)
oListModel1.setPropertyValue ("Dropdown", True)
oListModel1.setPropertyValue ("StringItemList", mLabels)
mSelected (0) = 0
oListModel1.setPropertyValue ("SelectedItems", mSelected)
oDialogModel.insertByName ("lstGroup", oListModel1)
' Adds the prompt.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 5)
oTextModel.setPropertyValue ("PositionY", 30)
oTextModel.setPropertyValue ("Height", 10)
oTextModel.setPropertyValue ("Width", 85)
oTextModel.setPropertyValue ("Label", "Second score column:")
oTextModel.setPropertyValue ("MultiLine", True)
oTextModel.setPropertyValue ("TabIndex", 1)
oDialogModel.insertByName ("txtPromptScore", oTextModel)
' Adds the drop down list
oListModel2 = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlListBoxModel")
oListModel2.setPropertyValue ("PositionX", 5)
oListModel2.setPropertyValue ("PositionY", 40)
oListModel2.setPropertyValue ("Height", 10)
oListModel2.setPropertyValue ("Width", 85)
oListModel2.setPropertyValue ("Dropdown", True)
oListModel2.setPropertyValue ("StringItemList", mLabels)
mSelected (0) = 1
oListModel2.setPropertyValue ("SelectedItems", mSelected)
oDialogModel.insertByName ("lstScore", oListModel2)
' Adds the buttons.
oButtonModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlButtonModel")
oButtonModel.setPropertyValue ("PositionX", 5)
oButtonModel.setPropertyValue ("PositionY", 60)
oButtonModel.setPropertyValue ("Height", 15)
oButtonModel.setPropertyValue ("Width", 40)
oButtonModel.setPropertyValue ("PushButtonType", _
com.sun.star.awt.PushButtonType.CANCEL)
oDialogModel.insertByName ("btnClose", oButtonModel)
oButtonModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlButtonModel")
oButtonModel.setPropertyValue ("PositionX", 50)
oButtonModel.setPropertyValue ("PositionY", 60)
oButtonModel.setPropertyValue ("Height", 15)
oButtonModel.setPropertyValue ("Width", 40)
oButtonModel.setPropertyValue ("PushButtonType", _
com.sun.star.awt.PushButtonType.OK)
oButtonModel.setPropertyValue ("DefaultButton", True)
oDialogModel.insertByName ("btnOK", oButtonModel)
' Adds the dialog model to the control and runs it.
oDialog = CreateUnoService ("com.sun.star.awt.UnoControlDialog")
oDialog.setModel (oDialogModel)
oDialog.setVisible (True)
nResult = oDialog.execute
oDialog.dispose
' Cancelled
If nResult = 0 Then
Exit Sub
End If
nColumn = oListModel1.getPropertyValue ("SelectedItems") (0)
oRange1 = oRange.getCellRangeByPosition ( _
nColumn, 0, nColumn, oRange.getRows.getCount - 1)
nColumn = oListModel2.getPropertyValue ("SelectedItems") (0)
oRange2 = oRange.getCellRangeByPosition ( _
nColumn, 0, nColumn, oRange.getRows.getCount - 1)
' Checks the existing report
oSheets = ThisComponent.getSheets
sSheetName = oRange1.getSpreadsheet.getName
sExisted = ""
If oSheets.hasByName (sSheetName & "_correl") Then
sExisted = sExisted & ", """ & sSheetName & "_correl"""
End If
If sExisted <> "" Then
sExisted = Right (sExisted, Len (sExisted) - 2)
If InStr (sExisted, ",") > 0 Then
sExisted = "Spreadsheets " & sExisted & " exist. Overwrite?"
Else
sExisted = "Spreadsheet " & sExisted & " exists. Overwrite?"
End If
nResult = MsgBox(sExisted, MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION)
If nResult = IDNO Then
Exit Sub
End If
' Drops the existing report
If oSheets.hasByName (sSheetName & "_correl") Then
oSheets.removeByname (sSheetName & "_correl")
End If
End If
' Reports the paired T-test.
subReportCorrelation (ThisComponent, oRange1, oRange2)
' Makes the report sheet active.
oSheet = oSheets.getByName (sSheetName & "_correl")
ThisComponent.getCurrentController.setActiveSheet (oSheet)
End Sub
' subTestCorrelation: Tests the Pearsons correlation coefficient report ' subTestCorrelation: Tests the Pearsons correlation coefficient report
Sub subTestCorrelation Sub subTestCorrelation
Dim oDoc As Object, oSheets As Object, sSheetName As String Dim oDoc As Object, oSheets As Object, sSheetName As String
Dim oSheet As Object, oRange As Object Dim oSheet As Object, oXRange As Object, oYRange As Object
oDoc = fnFindStatsTestDocument oDoc = fnFindStatsTestDocument
If oDoc = Null Then If IsNull (oDoc) Then
MsgBox "Cannot find statstest.ods in the opened documents." MsgBox "Cannot find statstest.ods in the opened documents."
Exit Sub Exit Sub
End If End If
@ -24,12 +178,13 @@ Sub subTestCorrelation
oSheets.removeByName (sSheetName & "_correl") oSheets.removeByName (sSheetName & "_correl")
End If End If
oSheet = oSheets.getByName (sSheetName) oSheet = oSheets.getByName (sSheetName)
oRange = oSheet.getCellRangeByName ("B3:C13") oXRange = oSheet.getCellRangeByName ("B3:B13")
subReportCorrelation (oDoc, oRange) oYRange = oSheet.getCellRangeByName ("C3:C13")
subReportCorrelation (oDoc, oXRange, oYRange)
End Sub End Sub
' subReportCorrelation: Reports the Pearsons correlation coefficient ' subReportCorrelation: Reports the Pearsons correlation coefficient
Sub subReportCorrelation (oDoc As Object, oDataRange As Object) Sub subReportCorrelation (oDoc As Object, oDataXRange As Object, oDataYRange As Object)
Dim oSheets As Object, sSheetName As String Dim oSheets As Object, sSheetName As String
Dim mNames () As String, nI As Integer, nSheetIndex As Integer Dim mNames () As String, nI As Integer, nSheetIndex As Integer
Dim oSheet As Object, oColumns As Object, nRow As Integer Dim oSheet As Object, oColumns As Object, nRow As Integer
@ -44,7 +199,7 @@ Sub subReportCorrelation (oDoc As Object, oDataRange As Object)
Dim sCellN As String, sCellR As String Dim sCellN As String, sCellR As String
oSheets = oDoc.getSheets oSheets = oDoc.getSheets
sSheetName = oDataRange.getSpreadsheet.getName sSheetName = oDataXRange.getSpreadsheet.getName
mNames = oSheets.getElementNames mNames = oSheets.getElementNames
For nI = 0 To UBound (mNames) For nI = 0 To UBound (mNames)
If mNames (nI) = sSheetName Then If mNames (nI) = sSheetName Then
@ -54,11 +209,11 @@ Sub subReportCorrelation (oDoc As Object, oDataRange As Object)
oSheets.insertNewByName (sSheetName & "_correl", nSheetIndex + 1) oSheets.insertNewByName (sSheetName & "_correl", nSheetIndex + 1)
oSheet = oSheets.getByName (sSheetName & "_correl") oSheet = oSheets.getByName (sSheetName & "_correl")
nN = oDataRange.getRows.getCount - 1 nN = oDataXRange.getRows.getCount - 1
sCellXLabel = fnGetRangeName (oDataRange.getCellByPosition (0, 0)) sCellXLabel = fnGetRangeName (oDataXRange.getCellByPosition (0, 0))
sCellsXData = fnGetRangeName (oDataRange.getCellRangeByPosition (0, 1, 0, nN)) sCellsXData = fnGetRangeName (oDataXRange.getCellRangeByPosition (0, 1, 0, nN))
sCellYLabel = fnGetRangeName (oDataRange.getCellByPosition (1, 0)) sCellYLabel = fnGetRangeName (oDataYRange.getCellByPosition (0, 0))
sCellsYData = fnGetRangeName (oDataRange.getCellRangeByPosition (1, 1, 1, nN)) sCellsYData = fnGetRangeName (oDataYRange.getCellRangeByPosition (0, 1, 0, nN))
' Obtains the format parameters for the report. ' Obtains the format parameters for the report.
nFormatN = fnQueryFormat (oDoc, "#,##0") nFormatN = fnQueryFormat (oDoc, "#,##0")

View File

@ -1,14 +1,169 @@
' _2PTTest: The macros to for generating the report of paired T-Test ' _2PTTest: The macros to for generating the report of paired T-Test
' by imacat <imacat@mail.imacat.idv.tw>, 2016-08-11 ' by imacat <imacat@mail.imacat.idv.tw>, 2016-08-11
Option Explicit Option Explicit
' subRunPairedTTest: Runs the paired T-test.
Sub subRunPairedTTest As Object
Dim oRange As Object
Dim mLabels () As String, nI As Integer, mSelected (0) As Integer
Dim oDialogModel As Object, oDialog As Object, nResult As Integer
Dim oTextModel As Object, oListModel1 As Object, oListModel2 As Object
Dim oButtonModel As Object
Dim nColumn As Integer, oRange1 As Object, oRange2 As Object
Dim oSheets As Object, sSheetName As String, sExisted As String
Dim oSheet As Object
' Asks the user for the data range
oRange = fnAskDataRange (ThisComponent)
If IsNull (oRange) Then
Exit Sub
End If
ReDim mLabels (oRange.getColumns.getCount - 1) As String
For nI = 0 To oRange.getColumns.getCount - 1
mLabels (nI) = oRange.getCellByPosition (nI, 0).getString
Next nI
' Creates a dialog
oDialogModel = CreateUnoService ( _
"com.sun.star.awt.UnoControlDialogModel")
oDialogModel.setPropertyValue ("PositionX", 200)
oDialogModel.setPropertyValue ("PositionY", 200)
oDialogModel.setPropertyValue ("Height", 80)
oDialogModel.setPropertyValue ("Width", 95)
oDialogModel.setPropertyValue ("Title", "Step 2/2: Specify the data")
' Adds the prompt.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 5)
oTextModel.setPropertyValue ("PositionY", 5)
oTextModel.setPropertyValue ("Height", 10)
oTextModel.setPropertyValue ("Width", 85)
oTextModel.setPropertyValue ("Label", "First score column:")
oTextModel.setPropertyValue ("MultiLine", True)
oTextModel.setPropertyValue ("TabIndex", 1)
oDialogModel.insertByName ("txtPromptGroup", oTextModel)
' Adds the drop down list
oListModel1 = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlListBoxModel")
oListModel1.setPropertyValue ("PositionX", 5)
oListModel1.setPropertyValue ("PositionY", 15)
oListModel1.setPropertyValue ("Height", 10)
oListModel1.setPropertyValue ("Width", 85)
oListModel1.setPropertyValue ("Dropdown", True)
oListModel1.setPropertyValue ("StringItemList", mLabels)
mSelected (0) = 0
oListModel1.setPropertyValue ("SelectedItems", mSelected)
oDialogModel.insertByName ("lstGroup", oListModel1)
' Adds the prompt.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 5)
oTextModel.setPropertyValue ("PositionY", 30)
oTextModel.setPropertyValue ("Height", 10)
oTextModel.setPropertyValue ("Width", 85)
oTextModel.setPropertyValue ("Label", "Second score column:")
oTextModel.setPropertyValue ("MultiLine", True)
oTextModel.setPropertyValue ("TabIndex", 1)
oDialogModel.insertByName ("txtPromptScore", oTextModel)
' Adds the drop down list
oListModel2 = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlListBoxModel")
oListModel2.setPropertyValue ("PositionX", 5)
oListModel2.setPropertyValue ("PositionY", 40)
oListModel2.setPropertyValue ("Height", 10)
oListModel2.setPropertyValue ("Width", 85)
oListModel2.setPropertyValue ("Dropdown", True)
oListModel2.setPropertyValue ("StringItemList", mLabels)
mSelected (0) = 1
oListModel2.setPropertyValue ("SelectedItems", mSelected)
oDialogModel.insertByName ("lstScore", oListModel2)
' Adds the buttons.
oButtonModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlButtonModel")
oButtonModel.setPropertyValue ("PositionX", 5)
oButtonModel.setPropertyValue ("PositionY", 60)
oButtonModel.setPropertyValue ("Height", 15)
oButtonModel.setPropertyValue ("Width", 40)
oButtonModel.setPropertyValue ("PushButtonType", _
com.sun.star.awt.PushButtonType.CANCEL)
oDialogModel.insertByName ("btnClose", oButtonModel)
oButtonModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlButtonModel")
oButtonModel.setPropertyValue ("PositionX", 50)
oButtonModel.setPropertyValue ("PositionY", 60)
oButtonModel.setPropertyValue ("Height", 15)
oButtonModel.setPropertyValue ("Width", 40)
oButtonModel.setPropertyValue ("PushButtonType", _
com.sun.star.awt.PushButtonType.OK)
oButtonModel.setPropertyValue ("DefaultButton", True)
oDialogModel.insertByName ("btnOK", oButtonModel)
' Adds the dialog model to the control and runs it.
oDialog = CreateUnoService ("com.sun.star.awt.UnoControlDialog")
oDialog.setModel (oDialogModel)
oDialog.setVisible (True)
nResult = oDialog.execute
oDialog.dispose
' Cancelled
If nResult = 0 Then
Exit Sub
End If
nColumn = oListModel1.getPropertyValue ("SelectedItems") (0)
oRange1 = oRange.getCellRangeByPosition ( _
nColumn, 0, nColumn, oRange.getRows.getCount - 1)
nColumn = oListModel2.getPropertyValue ("SelectedItems") (0)
oRange2 = oRange.getCellRangeByPosition ( _
nColumn, 0, nColumn, oRange.getRows.getCount - 1)
' Checks the existing report
oSheets = ThisComponent.getSheets
sSheetName = oRange1.getSpreadsheet.getName
sExisted = ""
If oSheets.hasByName (sSheetName & "_ttest") Then
sExisted = sExisted & ", """ & sSheetName & "_ttest"""
End If
If sExisted <> "" Then
sExisted = Right (sExisted, Len (sExisted) - 2)
If InStr (sExisted, ",") > 0 Then
sExisted = "Spreadsheets " & sExisted & " exist. Overwrite?"
Else
sExisted = "Spreadsheet " & sExisted & " exists. Overwrite?"
End If
nResult = MsgBox(sExisted, MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION)
If nResult = IDNO Then
Exit Sub
End If
' Drops the existing report
If oSheets.hasByName (sSheetName & "_ttest") Then
oSheets.removeByname (sSheetName & "_ttest")
End If
End If
' Reports the paired T-test.
subReportPairedTTest (ThisComponent, oRange1, oRange2)
' Makes the report sheet active.
oSheet = oSheets.getByName (sSheetName & "_ttest")
ThisComponent.getCurrentController.setActiveSheet (oSheet)
End Sub
' subTestPairedTTest: Tests the paired T-test report ' subTestPairedTTest: Tests the paired T-test report
Sub subTestPairedTTest Sub subTestPairedTTest
Dim oDoc As Object, oSheets As Object, sSheetName As String Dim oDoc As Object, oSheets As Object, sSheetName As String
Dim oSheet As Object, oRange As Object Dim oSheet As Object, oXRange As Object, oYRange As Object
oDoc = fnFindStatsTestDocument oDoc = fnFindStatsTestDocument
If oDoc = Null Then If IsNull (oDoc) Then
MsgBox "Cannot find statstest.ods in the opened documents." MsgBox "Cannot find statstest.ods in the opened documents."
Exit Sub Exit Sub
End If End If
@ -23,12 +178,13 @@ Sub subTestPairedTTest
oSheets.removeByName (sSheetName & "_ttest") oSheets.removeByName (sSheetName & "_ttest")
End If End If
oSheet = oSheets.getByName (sSheetName) oSheet = oSheets.getByName (sSheetName)
oRange = oSheet.getCellRangeByName ("B3:C15") oXRange = oSheet.getCellRangeByName ("B3:B15")
subReportPairedTTest (oDoc, oRange) oYRange = oSheet.getCellRangeByName ("C3:C15")
subReportPairedTTest (oDoc, oXRange, oYRange)
End Sub End Sub
' subReportPairedTTest: Reports the paired T-test ' subReportPairedTTest: Reports the paired T-test
Sub subReportPairedTTest (oDoc As Object, oDataRange As Object) Sub subReportPairedTTest (oDoc As Object, oDataXRange As Object, oDataYRange As Object)
Dim oSheets As Object, sSheetName As String Dim oSheets As Object, sSheetName As String
Dim mNames () As String, nI As Integer, nSheetIndex As Integer Dim mNames () As String, nI As Integer, nSheetIndex As Integer
Dim oSheet As Object, oColumns As Object, nRow As Integer Dim oSheet As Object, oColumns As Object, nRow As Integer
@ -45,7 +201,7 @@ Sub subReportPairedTTest (oDoc As Object, oDataRange As Object)
Dim sCellN As String, sCellXYS As String, sCellR As String Dim sCellN As String, sCellXYS As String, sCellR As String
oSheets = oDoc.getSheets oSheets = oDoc.getSheets
sSheetName = oDataRange.getSpreadsheet.getName sSheetName = oDataXRange.getSpreadsheet.getName
mNames = oSheets.getElementNames mNames = oSheets.getElementNames
For nI = 0 To UBound (mNames) For nI = 0 To UBound (mNames)
If mNames (nI) = sSheetName Then If mNames (nI) = sSheetName Then
@ -55,11 +211,11 @@ Sub subReportPairedTTest (oDoc As Object, oDataRange As Object)
oSheets.insertNewByName (sSheetName & "_ttest", nSheetIndex + 1) oSheets.insertNewByName (sSheetName & "_ttest", nSheetIndex + 1)
oSheet = oSheets.getByName (sSheetName & "_ttest") oSheet = oSheets.getByName (sSheetName & "_ttest")
nN = oDataRange.getRows.getCount - 1 nN = oDataXRange.getRows.getCount - 1
sCellXLabel = fnGetRangeName (oDataRange.getCellByPosition (0, 0)) sCellXLabel = fnGetRangeName (oDataXRange.getCellByPosition (0, 0))
sCellsXData = fnGetRangeName (oDataRange.getCellRangeByPosition (0, 1, 0, nN)) sCellsXData = fnGetRangeName (oDataXRange.getCellRangeByPosition (0, 1, 0, nN))
sCellYLabel = fnGetRangeName (oDataRange.getCellByPosition (1, 0)) sCellYLabel = fnGetRangeName (oDataYRange.getCellByPosition (0, 0))
sCellsYData = fnGetRangeName (oDataRange.getCellRangeByPosition (1, 1, 1, nN)) sCellsYData = fnGetRangeName (oDataYRange.getCellRangeByPosition (0, 1, 0, nN))
' Obtains the format parameters for the report. ' Obtains the format parameters for the report.
nFormatN = fnQueryFormat (oDoc, "#,##0") nFormatN = fnQueryFormat (oDoc, "#,##0")

View File

@ -1,14 +1,175 @@
' _3ITTest: The macros to for generating the report of independent T-Test ' _3ITTest: The macros to for generating the report of independent T-Test
' by imacat <imacat@mail.imacat.idv.tw>, 2016-08-24 ' by imacat <imacat@mail.imacat.idv.tw>, 2016-08-24
Option Explicit Option Explicit
' subTestIndependentTTest: Tests the independent T-test report ' subRunIndependentTTest: Runs the independent T-test.
Sub subRunIndependentTTest As Object
Dim oRange As Object
Dim mLabels () As String, nI As Integer, mSelected (0) As Integer
Dim oDialogModel As Object, oDialog As Object, nResult As Integer
Dim oTextModel As Object, oListModel1 As Object, oListModel2 As Object
Dim oButtonModel As Object
Dim nColumn As Integer, oRange1 As Object, oRange2 As Object
Dim oSheets As Object, sSheetName As String, sExisted As String
Dim oSheet As Object
' Asks the user for the data range
oRange = fnAskDataRange (ThisComponent)
If IsNull (oRange) Then
Exit Sub
End If
ReDim mLabels (oRange.getColumns.getCount - 1) As String
For nI = 0 To oRange.getColumns.getCount - 1
mLabels (nI) = oRange.getCellByPosition (nI, 0).getString
Next nI
' Creates a dialog
oDialogModel = CreateUnoService ( _
"com.sun.star.awt.UnoControlDialogModel")
oDialogModel.setPropertyValue ("PositionX", 200)
oDialogModel.setPropertyValue ("PositionY", 200)
oDialogModel.setPropertyValue ("Height", 80)
oDialogModel.setPropertyValue ("Width", 95)
oDialogModel.setPropertyValue ("Title", "Step 2/2: Specify the data")
' Adds the prompt.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 5)
oTextModel.setPropertyValue ("PositionY", 5)
oTextModel.setPropertyValue ("Height", 10)
oTextModel.setPropertyValue ("Width", 85)
oTextModel.setPropertyValue ("Label", "Group column:")
oTextModel.setPropertyValue ("MultiLine", True)
oTextModel.setPropertyValue ("TabIndex", 1)
oDialogModel.insertByName ("txtPromptGroup", oTextModel)
' Adds the drop down list
oListModel1 = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlListBoxModel")
oListModel1.setPropertyValue ("PositionX", 5)
oListModel1.setPropertyValue ("PositionY", 15)
oListModel1.setPropertyValue ("Height", 10)
oListModel1.setPropertyValue ("Width", 85)
oListModel1.setPropertyValue ("Dropdown", True)
oListModel1.setPropertyValue ("StringItemList", mLabels)
mSelected (0) = 0
oListModel1.setPropertyValue ("SelectedItems", mSelected)
oDialogModel.insertByName ("lstGroup", oListModel1)
' Adds the prompt.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 5)
oTextModel.setPropertyValue ("PositionY", 30)
oTextModel.setPropertyValue ("Height", 10)
oTextModel.setPropertyValue ("Width", 85)
oTextModel.setPropertyValue ("Label", "Score column:")
oTextModel.setPropertyValue ("MultiLine", True)
oTextModel.setPropertyValue ("TabIndex", 1)
oDialogModel.insertByName ("txtPromptScore", oTextModel)
' Adds the drop down list
oListModel2 = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlListBoxModel")
oListModel2.setPropertyValue ("PositionX", 5)
oListModel2.setPropertyValue ("PositionY", 40)
oListModel2.setPropertyValue ("Height", 10)
oListModel2.setPropertyValue ("Width", 85)
oListModel2.setPropertyValue ("Dropdown", True)
oListModel2.setPropertyValue ("StringItemList", mLabels)
mSelected (0) = 1
oListModel2.setPropertyValue ("SelectedItems", mSelected)
oDialogModel.insertByName ("lstScore", oListModel2)
' Adds the buttons.
oButtonModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlButtonModel")
oButtonModel.setPropertyValue ("PositionX", 5)
oButtonModel.setPropertyValue ("PositionY", 60)
oButtonModel.setPropertyValue ("Height", 15)
oButtonModel.setPropertyValue ("Width", 40)
oButtonModel.setPropertyValue ("PushButtonType", _
com.sun.star.awt.PushButtonType.CANCEL)
oDialogModel.insertByName ("btnClose", oButtonModel)
oButtonModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlButtonModel")
oButtonModel.setPropertyValue ("PositionX", 50)
oButtonModel.setPropertyValue ("PositionY", 60)
oButtonModel.setPropertyValue ("Height", 15)
oButtonModel.setPropertyValue ("Width", 40)
oButtonModel.setPropertyValue ("PushButtonType", _
com.sun.star.awt.PushButtonType.OK)
oButtonModel.setPropertyValue ("DefaultButton", True)
oDialogModel.insertByName ("btnOK", oButtonModel)
' Adds the dialog model to the control and runs it.
oDialog = CreateUnoService ("com.sun.star.awt.UnoControlDialog")
oDialog.setModel (oDialogModel)
oDialog.setVisible (True)
nResult = oDialog.execute
oDialog.dispose
' Cancelled
If nResult = 0 Then
Exit Sub
End If
nColumn = oListModel1.getPropertyValue ("SelectedItems") (0)
oRange1 = oRange.getCellRangeByPosition ( _
nColumn, 0, nColumn, oRange.getRows.getCount - 1)
nColumn = oListModel2.getPropertyValue ("SelectedItems") (0)
oRange2 = oRange.getCellRangeByPosition ( _
nColumn, 0, nColumn, oRange.getRows.getCount - 1)
' Checks the existing report
oSheets = ThisComponent.getSheets
sSheetName = oRange1.getSpreadsheet.getName
sExisted = ""
If oSheets.hasByName (sSheetName & "_ttest") Then
sExisted = sExisted & ", """ & sSheetName & "_ttest"""
End If
If oSheets.hasByName (sSheetName & "_ttesttmp") Then
sExisted = sExisted & ", """ & sSheetName & "_ttesttmp"""
End If
If sExisted <> "" Then
sExisted = Right (sExisted, Len (sExisted) - 2)
If InStr (sExisted, ",") > 0 Then
sExisted = "Spreadsheets " & sExisted & " exist. Overwrite?"
Else
sExisted = "Spreadsheet " & sExisted & " exists. Overwrite?"
End If
nResult = MsgBox(sExisted, MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION)
If nResult = IDNO Then
Exit Sub
End If
' Drops the existing report
If oSheets.hasByName (sSheetName & "_ttest") Then
oSheets.removeByname (sSheetName & "_ttest")
End If
If oSheets.hasByName (sSheetName & "_ttesttmp") Then
oSheets.removeByname (sSheetName & "_ttesttmp")
End If
End If
' Reports the independent T-test.
subReportIndependentTTest (ThisComponent, oRange1, oRange2)
' Makes the report sheet active.
oSheet = oSheets.getByName (sSheetName & "_ttest")
ThisComponent.getCurrentController.setActiveSheet (oSheet)
End Sub
' subTestIndependentTTest: Tests the independent T-test report.
Sub subTestIndependentTTest Sub subTestIndependentTTest
Dim oDoc As Object, oSheets As Object, sSheetName As String Dim oDoc As Object, oSheets As Object, sSheetName As String
Dim oSheet As Object, oRange As Object Dim oSheet As Object, oLabelColumn As Object, oScoreColumn As Object
oDoc = fnFindStatsTestDocument oDoc = fnFindStatsTestDocument
If oDoc = Null Then If IsNull (oDoc) Then
MsgBox "Cannot find statstest.ods in the opened documents." MsgBox "Cannot find statstest.ods in the opened documents."
Exit Sub Exit Sub
End If End If
@ -26,12 +187,13 @@ Sub subTestIndependentTTest
oSheets.removeByName (sSheetName & "_ttesttmp") oSheets.removeByName (sSheetName & "_ttesttmp")
End If End If
oSheet = oSheets.getByName (sSheetName) oSheet = oSheets.getByName (sSheetName)
oRange = oSheet.getCellRangeByName ("A15:B34") oLabelColumn = oSheet.getCellRangeByName ("A15:A34")
subReportIndependentTTest (oDoc, oRange) oScoreColumn = oSheet.getCellRangeByName ("B15:B34")
subReportIndependentTTest (oDoc, oLabelColumn, oScoreColumn)
End Sub End Sub
' subReportIndependentTTest: Reports the independent T-test ' subReportIndependentTTest: Reports the independent T-test
Sub subReportIndependentTTest (oDoc As Object, oDataRange As Object) Sub subReportIndependentTTest (oDoc As Object, oLabelColumn As Object, oScoreColumn As Object)
Dim oSheets As Object, sSheetName As String Dim oSheets As Object, sSheetName As String
Dim mNames () As String, nI As Integer, nSheetIndex As Integer Dim mNames () As String, nI As Integer, nSheetIndex As Integer
Dim oSheet As Object, oColumns As Object, nRow As Integer Dim oSheet As Object, oColumns As Object, nRow As Integer
@ -48,7 +210,7 @@ Sub subReportIndependentTTest (oDoc As Object, oDataRange As Object)
Dim sCellF As String, sCellsN As String, sCellN As String Dim sCellF As String, sCellsN As String, sCellN As String
oSheets = oDoc.getSheets oSheets = oDoc.getSheets
sSheetName = oDataRange.getSpreadsheet.getName sSheetName = oLabelColumn.getSpreadsheet.getName
mNames = oSheets.getElementNames mNames = oSheets.getElementNames
For nI = 0 To UBound (mNames) For nI = 0 To UBound (mNames)
If mNames (nI) = sSheetName Then If mNames (nI) = sSheetName Then
@ -58,7 +220,7 @@ Sub subReportIndependentTTest (oDoc As Object, oDataRange As Object)
oSheets.insertNewByName (sSheetName & "_ttesttmp", nSheetIndex + 1) oSheets.insertNewByName (sSheetName & "_ttesttmp", nSheetIndex + 1)
oSheet = oSheets.getByName (sSheetName & "_ttesttmp") oSheet = oSheets.getByName (sSheetName & "_ttesttmp")
oTempDataRange = fnCollectIndependentTTestData (oDataRange, oSheet) oTempDataRange = fnCollectIndependentTTestData (oSheet, oLabelColumn, oScoreColumn)
oSheets.insertNewByName (sSheetName & "_ttest", nSheetIndex + 1) oSheets.insertNewByName (sSheetName & "_ttest", nSheetIndex + 1)
oSheet = oSheets.getByName (sSheetName & "_ttest") oSheet = oSheets.getByName (sSheetName & "_ttest")
@ -527,7 +689,7 @@ Sub subReportIndependentTTest (oDoc As Object, oDataRange As Object)
End Sub End Sub
' fnCollectIndependentTTestData: Collects the data for the independent T-test. ' fnCollectIndependentTTestData: Collects the data for the independent T-test.
Function fnCollectIndependentTTestData (oDataRange As Object, oReportSheet As Object) As Object Function fnCollectIndependentTTestData (oReportSheet As Object, oLabelColumn As Object, oScoreColumn As Object) As Object
Dim nRow As Integer, nNRow As Integer, sCellZMean As String, sCellsN As String Dim nRow As Integer, nNRow As Integer, sCellZMean As String, sCellsN As String
Dim oCell As Object, oCells As Object, oCursor As Object Dim oCell As Object, oCells As Object, oCursor As Object
Dim sCell As String, sLabel As String, sFormula As String Dim sCell As String, sLabel As String, sFormula As String
@ -540,8 +702,8 @@ Function fnCollectIndependentTTestData (oDataRange As Object, oReportSheet As Ob
sCellXLabel = "" sCellXLabel = ""
sCellYLabel = "" sCellYLabel = ""
For nRow = 1 To oDataRange.getRows.getCount - 1 For nRow = 1 To oLabelColumn.getRows.getCount - 1
oCell = oDataRange.getCellByPosition (0, nRow) oCell = oLabelColumn.getCellByPosition (0, nRow)
sLabel = oCell.getString sLabel = oCell.getString
If sLabel <> "" Then If sLabel <> "" Then
If sCellXLabel = "" Then If sCellXLabel = "" Then
@ -551,7 +713,7 @@ Function fnCollectIndependentTTestData (oDataRange As Object, oReportSheet As Ob
If sLabel <> sXLabel And sCellYLabel = "" Then If sLabel <> sXLabel And sCellYLabel = "" Then
sCellYLabel = fnGetRangeName (oCell) sCellYLabel = fnGetRangeName (oCell)
sYLabel = sLabel sYLabel = sLabel
nRow = oDataRange.getRows.getCount - 1 nRow = oLabelColumn.getRows.getCount - 1
End If End If
End If End If
End If End If
@ -568,15 +730,15 @@ Function fnCollectIndependentTTestData (oDataRange As Object, oReportSheet As Ob
' The data ' The data
nNX = 0 nNX = 0
nNY = 0 nNY = 0
For nRow = 1 To oDataRange.getRows.getCount - 1 For nRow = 1 To oLabelColumn.getRows.getCount - 1
If oDataRange.getCellByPosition (0, nRow).getString = sXLabel Then If oLabelColumn.getCellByPosition (0, nRow).getString = sXLabel Then
nNX = nNX + 1 nNX = nNX + 1
sFormula = "=" & fnGetRangeName (oDataRange.getCellByPosition (1, nRow)) sFormula = "=" & fnGetRangeName (oScoreColumn.getCellByPosition (0, nRow))
oReportSheet.getCellByPosition (0, nNX).setFormula (sFormula) oReportSheet.getCellByPosition (0, nNX).setFormula (sFormula)
Else Else
If oDataRange.getCellByPosition (0, nRow).getString = sYLabel Then If oLabelColumn.getCellByPosition (0, nRow).getString = sYLabel Then
nNY = nNY + 1 nNY = nNY + 1
sFormula = "=" & fnGetRangeName (oDataRange.getCellByPosition (1, nRow)) sFormula = "=" & fnGetRangeName (oScoreColumn.getCellByPosition (0, nRow))
oReportSheet.getCellByPosition (1, nNY).setFormula (sFormula) oReportSheet.getCellByPosition (1, nNY).setFormula (sFormula)
End If End If
End If End If

View File

@ -1,14 +1,175 @@
' _4ANOVA: The macros to for generating the report of ANOVA (Analyze of Variances) ' _4ANOVA: The macros to for generating the report of ANOVA (Analyze of Variances)
' by imacat <imacat@mail.imacat.idv.tw>, 2016-08-31 ' by imacat <imacat@mail.imacat.idv.tw>, 2016-08-31
Option Explicit Option Explicit
' subRunANOVA: Runs the ANOVA (Analyze of Variances).
Sub subRunANOVA As Object
Dim oRange As Object
Dim mLabels () As String, nI As Integer, mSelected (0) As Integer
Dim oDialogModel As Object, oDialog As Object, nResult As Integer
Dim oTextModel As Object, oListModel1 As Object, oListModel2 As Object
Dim oButtonModel As Object
Dim nColumn As Integer, oRange1 As Object, oRange2 As Object
Dim oSheets As Object, sSheetName As String, sExisted As String
Dim oSheet As Object
' Asks the user for the data range
oRange = fnAskDataRange (ThisComponent)
If IsNull (oRange) Then
Exit Sub
End If
ReDim mLabels (oRange.getColumns.getCount - 1) As String
For nI = 0 To oRange.getColumns.getCount - 1
mLabels (nI) = oRange.getCellByPosition (nI, 0).getString
Next nI
' Creates a dialog
oDialogModel = CreateUnoService ( _
"com.sun.star.awt.UnoControlDialogModel")
oDialogModel.setPropertyValue ("PositionX", 200)
oDialogModel.setPropertyValue ("PositionY", 200)
oDialogModel.setPropertyValue ("Height", 80)
oDialogModel.setPropertyValue ("Width", 95)
oDialogModel.setPropertyValue ("Title", "Step 2/2: Specify the data")
' Adds the prompt.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 5)
oTextModel.setPropertyValue ("PositionY", 5)
oTextModel.setPropertyValue ("Height", 10)
oTextModel.setPropertyValue ("Width", 85)
oTextModel.setPropertyValue ("Label", "Group column:")
oTextModel.setPropertyValue ("MultiLine", True)
oTextModel.setPropertyValue ("TabIndex", 1)
oDialogModel.insertByName ("txtPromptGroup", oTextModel)
' Adds the drop down list
oListModel1 = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlListBoxModel")
oListModel1.setPropertyValue ("PositionX", 5)
oListModel1.setPropertyValue ("PositionY", 15)
oListModel1.setPropertyValue ("Height", 10)
oListModel1.setPropertyValue ("Width", 85)
oListModel1.setPropertyValue ("Dropdown", True)
oListModel1.setPropertyValue ("StringItemList", mLabels)
mSelected (0) = 0
oListModel1.setPropertyValue ("SelectedItems", mSelected)
oDialogModel.insertByName ("lstGroup", oListModel1)
' Adds the prompt.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 5)
oTextModel.setPropertyValue ("PositionY", 30)
oTextModel.setPropertyValue ("Height", 10)
oTextModel.setPropertyValue ("Width", 85)
oTextModel.setPropertyValue ("Label", "Score column:")
oTextModel.setPropertyValue ("MultiLine", True)
oTextModel.setPropertyValue ("TabIndex", 1)
oDialogModel.insertByName ("txtPromptScore", oTextModel)
' Adds the drop down list
oListModel2 = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlListBoxModel")
oListModel2.setPropertyValue ("PositionX", 5)
oListModel2.setPropertyValue ("PositionY", 40)
oListModel2.setPropertyValue ("Height", 10)
oListModel2.setPropertyValue ("Width", 85)
oListModel2.setPropertyValue ("Dropdown", True)
oListModel2.setPropertyValue ("StringItemList", mLabels)
mSelected (0) = 1
oListModel2.setPropertyValue ("SelectedItems", mSelected)
oDialogModel.insertByName ("lstScore", oListModel2)
' Adds the buttons.
oButtonModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlButtonModel")
oButtonModel.setPropertyValue ("PositionX", 5)
oButtonModel.setPropertyValue ("PositionY", 60)
oButtonModel.setPropertyValue ("Height", 15)
oButtonModel.setPropertyValue ("Width", 40)
oButtonModel.setPropertyValue ("PushButtonType", _
com.sun.star.awt.PushButtonType.CANCEL)
oDialogModel.insertByName ("btnClose", oButtonModel)
oButtonModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlButtonModel")
oButtonModel.setPropertyValue ("PositionX", 50)
oButtonModel.setPropertyValue ("PositionY", 60)
oButtonModel.setPropertyValue ("Height", 15)
oButtonModel.setPropertyValue ("Width", 40)
oButtonModel.setPropertyValue ("PushButtonType", _
com.sun.star.awt.PushButtonType.OK)
oButtonModel.setPropertyValue ("DefaultButton", True)
oDialogModel.insertByName ("btnOK", oButtonModel)
' Adds the dialog model to the control and runs it.
oDialog = CreateUnoService ("com.sun.star.awt.UnoControlDialog")
oDialog.setModel (oDialogModel)
oDialog.setVisible (True)
nResult = oDialog.execute
oDialog.dispose
' Cancelled
If nResult = 0 Then
Exit Sub
End If
nColumn = oListModel1.getPropertyValue ("SelectedItems") (0)
oRange1 = oRange.getCellRangeByPosition ( _
nColumn, 0, nColumn, oRange.getRows.getCount - 1)
nColumn = oListModel2.getPropertyValue ("SelectedItems") (0)
oRange2 = oRange.getCellRangeByPosition ( _
nColumn, 0, nColumn, oRange.getRows.getCount - 1)
' Checks the existing report
oSheets = ThisComponent.getSheets
sSheetName = oRange1.getSpreadsheet.getName
sExisted = ""
If oSheets.hasByName (sSheetName & "_anova") Then
sExisted = sExisted & ", """ & sSheetName & "_anova"""
End If
If oSheets.hasByName (sSheetName & "_anovatmp") Then
sExisted = sExisted & ", """ & sSheetName & "_anovatmp"""
End If
If sExisted <> "" Then
sExisted = Right (sExisted, Len (sExisted) - 2)
If InStr (sExisted, ",") > 0 Then
sExisted = "Spreadsheets " & sExisted & " exist. Overwrite?"
Else
sExisted = "Spreadsheet " & sExisted & " exists. Overwrite?"
End If
nResult = MsgBox(sExisted, MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION)
If nResult = IDNO Then
Exit Sub
End If
' Drops the existing report
If oSheets.hasByName (sSheetName & "_anova") Then
oSheets.removeByname (sSheetName & "_anova")
End If
If oSheets.hasByName (sSheetName & "_anovatmp") Then
oSheets.removeByname (sSheetName & "_anovatmp")
End If
End If
' Reports the ANOVA (Analyze of Variances)
subReportANOVA (ThisComponent, oRange1, oRange2)
' Makes the report sheet active.
oSheet = oSheets.getByName (sSheetName & "_anova")
ThisComponent.getCurrentController.setActiveSheet (oSheet)
End Sub
' subTestANOVA: Tests the ANOVA (Analyze of Variances) report ' subTestANOVA: Tests the ANOVA (Analyze of Variances) report
Sub subTestANOVA Sub subTestANOVA
Dim oDoc As Object, oSheets As Object, sSheetName As String Dim oDoc As Object, oSheets As Object, sSheetName As String
Dim oSheet As Object, oRange As Object Dim oSheet As Object, oLabelColumn As Object, oScoreColumn As Object
oDoc = fnFindStatsTestDocument oDoc = fnFindStatsTestDocument
If oDoc = Null Then If IsNull (oDoc) Then
MsgBox "Cannot find statstest.ods in the opened documents." MsgBox "Cannot find statstest.ods in the opened documents."
Exit Sub Exit Sub
End If End If
@ -26,12 +187,13 @@ Sub subTestANOVA
oSheets.removeByName (sSheetName & "_anovatmp") oSheets.removeByName (sSheetName & "_anovatmp")
End If End If
oSheet = oSheets.getByName (sSheetName) oSheet = oSheets.getByName (sSheetName)
oRange = oSheet.getCellRangeByName ("A13:B35") oLabelColumn = oSheet.getCellRangeByName ("A13:A35")
subReportANOVA (oDoc, oRange) oScoreColumn = oSheet.getCellRangeByName ("B13:B35")
subReportANOVA (oDoc, oLabelColumn, oScoreColumn)
End Sub End Sub
' subReportANOVA: Reports the ANOVA (Analyze of Variances) ' subReportANOVA: Reports the ANOVA (Analyze of Variances)
Sub subReportANOVA (oDoc As Object, oDataRange As Object) Sub subReportANOVA (oDoc As Object, oLabelColumn As Object, oScoreColumn As Object)
Dim oSheets As Object, sSheetName As String Dim oSheets As Object, sSheetName As String
Dim nI As Integer, nJ As Integer Dim nI As Integer, nJ As Integer
Dim mNames () As String, nSheetIndex As Integer Dim mNames () As String, nSheetIndex As Integer
@ -54,7 +216,7 @@ Sub subReportANOVA (oDoc As Object, oDataRange As Object)
Dim sCellMeanDiff As String Dim sCellMeanDiff As String
oSheets = oDoc.getSheets oSheets = oDoc.getSheets
sSheetName = oDataRange.getSpreadsheet.getName sSheetName = oLabelColumn.getSpreadsheet.getName
mNames = oSheets.getElementNames mNames = oSheets.getElementNames
For nI = 0 To UBound (mNames) For nI = 0 To UBound (mNames)
If mNames (nI) = sSheetName Then If mNames (nI) = sSheetName Then
@ -64,7 +226,7 @@ Sub subReportANOVA (oDoc As Object, oDataRange As Object)
oSheets.insertNewByName (sSheetName & "_anovatmp", nSheetIndex + 1) oSheets.insertNewByName (sSheetName & "_anovatmp", nSheetIndex + 1)
oSheet = oSheets.getByName (sSheetName & "_anovatmp") oSheet = oSheets.getByName (sSheetName & "_anovatmp")
oTempDataRange = fnCollectANOVAData (oDataRange, oSheet) oTempDataRange = fnCollectANOVAData (oSheet, oLabelColumn, oScoreColumn)
nGroups = oTempDataRange.getColumns.getCount / 3 nGroups = oTempDataRange.getColumns.getCount / 3
oSheets.insertNewByName (sSheetName & "_anova", nSheetIndex + 1) oSheets.insertNewByName (sSheetName & "_anova", nSheetIndex + 1)
@ -852,7 +1014,7 @@ Sub subReportANOVA (oDoc As Object, oDataRange As Object)
End Sub End Sub
' fnCollectANOVAData: Collects the data for the ANOVA (Analyze of Variances). ' fnCollectANOVAData: Collects the data for the ANOVA (Analyze of Variances).
Function fnCollectANOVAData (oDataRange As Object, oReportSheet As Object) As Object Function fnCollectANOVAData (oReportSheet As Object, oLabelColumn As Object, oScoreColumn As Object) As Object
Dim nRow As Integer, nColumn As Integer, nI As Integer Dim nRow As Integer, nColumn As Integer, nI As Integer
Dim nNRow As Integer, sCellZMean As String, sCellsN As String Dim nNRow As Integer, sCellZMean As String, sCellsN As String
Dim oCell As Object, oCells As Object, oCursor As Object Dim oCell As Object, oCells As Object, oCursor As Object
@ -865,8 +1027,8 @@ Function fnCollectANOVAData (oDataRange As Object, oReportSheet As Object) As Ob
sLabels = " " sLabels = " "
nGroups = 0 nGroups = 0
For nRow = 1 To oDataRange.getRows.getCount - 1 For nRow = 1 To oLabelColumn.getRows.getCount - 1
sLabel = oDataRange.getCellByPosition (0, nRow).getString sLabel = oLabelColumn.getCellByPosition (0, nRow).getString
If InStr (sLabels, " " & sLabel & " ") = 0 Then If InStr (sLabels, " " & sLabel & " ") = 0 Then
sLabels = sLabels & sLabel & " " sLabels = sLabels & sLabel & " "
nGroups = nGroups + 1 nGroups = nGroups + 1
@ -880,8 +1042,8 @@ Function fnCollectANOVAData (oDataRange As Object, oReportSheet As Object) As Ob
sLabels = " " sLabels = " "
nGroups = 0 nGroups = 0
For nRow = 1 To oDataRange.getRows.getCount - 1 For nRow = 1 To oLabelColumn.getRows.getCount - 1
oCell = oDataRange.getCellByPosition (0, nRow) oCell = oLabelColumn.getCellByPosition (0, nRow)
sLabel = oCell.getString sLabel = oCell.getString
If InStr (sLabels, " " & sLabel & " ") = 0 Then If InStr (sLabels, " " & sLabel & " ") = 0 Then
sLabels = sLabels & sLabel & " " sLabels = sLabels & sLabel & " "
@ -902,8 +1064,8 @@ Function fnCollectANOVAData (oDataRange As Object, oReportSheet As Object) As Ob
For nI = 0 To nGroups - 1 For nI = 0 To nGroups - 1
mN (nI) = 0 mN (nI) = 0
Next nI Next nI
For nRow = 1 To oDataRange.getRows.getCount - 1 For nRow = 1 To oLabelColumn.getRows.getCount - 1
sLabel = oDataRange.getCellByPosition (0, nRow).getString sLabel = oLabelColumn.getCellByPosition (0, nRow).getString
For nI = 0 To nGroups - 1 For nI = 0 To nGroups - 1
If sLabel = mLabels (nI) Then If sLabel = mLabels (nI) Then
nColumn = nI nColumn = nI
@ -911,7 +1073,7 @@ Function fnCollectANOVAData (oDataRange As Object, oReportSheet As Object) As Ob
End If End If
Next nI Next nI
mN (nColumn) = mN (nColumn) + 1 mN (nColumn) = mN (nColumn) + 1
sFormula = "=" & fnGetRangeName (oDataRange.getCellByPosition (1, nRow)) sFormula = "=" & fnGetRangeName (oScoreColumn.getCellByPosition (0, nRow))
oCell = oReportSheet.getCellByPosition (nColumn, mN (nColumn)) oCell = oReportSheet.getCellByPosition (nColumn, mN (nColumn))
oCell.setFormula (sFormula) oCell.setFormula (sFormula)
Next nRow Next nRow

View File

@ -1,14 +1,169 @@
' _5Chi2GoF: The macros to for generating the report of Chi-square goodness of fit ' _5Chi2GoF: The macros to for generating the report of Chi-square goodness of fit
' by imacat <imacat@mail.imacat.idv.tw>, 2016-09-05 ' by imacat <imacat@mail.imacat.idv.tw>, 2016-09-05
Option Explicit Option Explicit
' subRunChi2GoodnessOfFit: Runs the chi-square goodness of fit.
Sub subRunChi2GoodnessOfFit As Object
Dim oRange As Object
Dim mLabels () As String, nI As Integer, mSelected (0) As Integer
Dim oDialogModel As Object, oDialog As Object, nResult As Integer
Dim oTextModel As Object, oListModel1 As Object, oListModel2 As Object
Dim oButtonModel As Object
Dim nColumn As Integer, oRange1 As Object, oRange2 As Object
Dim oSheets As Object, sSheetName As String, sExisted As String
Dim oSheet As Object
' Asks the user for the data range
oRange = fnAskDataRange (ThisComponent)
If IsNull (oRange) Then
Exit Sub
End If
ReDim mLabels (oRange.getColumns.getCount - 1) As String
For nI = 0 To oRange.getColumns.getCount - 1
mLabels (nI) = oRange.getCellByPosition (nI, 0).getString
Next nI
' Creates a dialog
oDialogModel = CreateUnoService ( _
"com.sun.star.awt.UnoControlDialogModel")
oDialogModel.setPropertyValue ("PositionX", 200)
oDialogModel.setPropertyValue ("PositionY", 200)
oDialogModel.setPropertyValue ("Height", 80)
oDialogModel.setPropertyValue ("Width", 95)
oDialogModel.setPropertyValue ("Title", "Step 2/2: Specify the data")
' Adds the prompt.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 5)
oTextModel.setPropertyValue ("PositionY", 5)
oTextModel.setPropertyValue ("Height", 10)
oTextModel.setPropertyValue ("Width", 85)
oTextModel.setPropertyValue ("Label", "Group (column) column:")
oTextModel.setPropertyValue ("MultiLine", True)
oTextModel.setPropertyValue ("TabIndex", 1)
oDialogModel.insertByName ("txtPromptGroup", oTextModel)
' Adds the drop down list
oListModel1 = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlListBoxModel")
oListModel1.setPropertyValue ("PositionX", 5)
oListModel1.setPropertyValue ("PositionY", 15)
oListModel1.setPropertyValue ("Height", 10)
oListModel1.setPropertyValue ("Width", 85)
oListModel1.setPropertyValue ("Dropdown", True)
oListModel1.setPropertyValue ("StringItemList", mLabels)
mSelected (0) = 0
oListModel1.setPropertyValue ("SelectedItems", mSelected)
oDialogModel.insertByName ("lstGroup", oListModel1)
' Adds the prompt.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 5)
oTextModel.setPropertyValue ("PositionY", 30)
oTextModel.setPropertyValue ("Height", 10)
oTextModel.setPropertyValue ("Width", 85)
oTextModel.setPropertyValue ("Label", "Event (row) column:")
oTextModel.setPropertyValue ("MultiLine", True)
oTextModel.setPropertyValue ("TabIndex", 1)
oDialogModel.insertByName ("txtPromptScore", oTextModel)
' Adds the drop down list
oListModel2 = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlListBoxModel")
oListModel2.setPropertyValue ("PositionX", 5)
oListModel2.setPropertyValue ("PositionY", 40)
oListModel2.setPropertyValue ("Height", 10)
oListModel2.setPropertyValue ("Width", 85)
oListModel2.setPropertyValue ("Dropdown", True)
oListModel2.setPropertyValue ("StringItemList", mLabels)
mSelected (0) = 1
oListModel2.setPropertyValue ("SelectedItems", mSelected)
oDialogModel.insertByName ("lstScore", oListModel2)
' Adds the buttons.
oButtonModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlButtonModel")
oButtonModel.setPropertyValue ("PositionX", 5)
oButtonModel.setPropertyValue ("PositionY", 60)
oButtonModel.setPropertyValue ("Height", 15)
oButtonModel.setPropertyValue ("Width", 40)
oButtonModel.setPropertyValue ("PushButtonType", _
com.sun.star.awt.PushButtonType.CANCEL)
oDialogModel.insertByName ("btnClose", oButtonModel)
oButtonModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlButtonModel")
oButtonModel.setPropertyValue ("PositionX", 50)
oButtonModel.setPropertyValue ("PositionY", 60)
oButtonModel.setPropertyValue ("Height", 15)
oButtonModel.setPropertyValue ("Width", 40)
oButtonModel.setPropertyValue ("PushButtonType", _
com.sun.star.awt.PushButtonType.OK)
oButtonModel.setPropertyValue ("DefaultButton", True)
oDialogModel.insertByName ("btnOK", oButtonModel)
' Adds the dialog model to the control and runs it.
oDialog = CreateUnoService ("com.sun.star.awt.UnoControlDialog")
oDialog.setModel (oDialogModel)
oDialog.setVisible (True)
nResult = oDialog.execute
oDialog.dispose
' Cancelled
If nResult = 0 Then
Exit Sub
End If
nColumn = oListModel1.getPropertyValue ("SelectedItems") (0)
oRange1 = oRange.getCellRangeByPosition ( _
nColumn, 0, nColumn, oRange.getRows.getCount - 1)
nColumn = oListModel2.getPropertyValue ("SelectedItems") (0)
oRange2 = oRange.getCellRangeByPosition ( _
nColumn, 0, nColumn, oRange.getRows.getCount - 1)
' Checks the existing report
oSheets = ThisComponent.getSheets
sSheetName = oRange1.getSpreadsheet.getName
sExisted = ""
If oSheets.hasByName (sSheetName & "_chi2") Then
sExisted = sExisted & ", """ & sSheetName & "_chi2"""
End If
If sExisted <> "" Then
sExisted = Right (sExisted, Len (sExisted) - 2)
If InStr (sExisted, ",") > 0 Then
sExisted = "Spreadsheets " & sExisted & " exist. Overwrite?"
Else
sExisted = "Spreadsheet " & sExisted & " exists. Overwrite?"
End If
nResult = MsgBox(sExisted, MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION)
If nResult = IDNO Then
Exit Sub
End If
' Drops the existing report
If oSheets.hasByName (sSheetName & "_chi2") Then
oSheets.removeByname (sSheetName & "_chi2")
End If
End If
' Reports the chi-square goodness of fit
subReportChi2GoodnessOfFit (ThisComponent, oRange1, oRange2)
' Makes the report sheet active.
oSheet = oSheets.getByName (sSheetName & "_chi2")
ThisComponent.getCurrentController.setActiveSheet (oSheet)
End Sub
' subTestChi2GoodnessOfFit: Tests the chi-square goodness of fit report ' subTestChi2GoodnessOfFit: Tests the chi-square goodness of fit report
Sub subTestChi2GoodnessOfFit Sub subTestChi2GoodnessOfFit
Dim oDoc As Object, oSheets As Object, sSheetName As String Dim oDoc As Object, oSheets As Object, sSheetName As String
Dim oSheet As Object, oRange As Object Dim oSheet As Object, oColumnColumn As Object, oRowColumn As Object
oDoc = fnFindStatsTestDocument oDoc = fnFindStatsTestDocument
If oDoc = Null Then If IsNull (oDoc) Then
MsgBox "Cannot find statstest.ods in the opened documents." MsgBox "Cannot find statstest.ods in the opened documents."
Exit Sub Exit Sub
End If End If
@ -23,12 +178,13 @@ Sub subTestChi2GoodnessOfFit
oSheets.removeByName (sSheetName & "_chi2") oSheets.removeByName (sSheetName & "_chi2")
End If End If
oSheet = oSheets.getByName (sSheetName) oSheet = oSheets.getByName (sSheetName)
oRange = oSheet.getCellRangeByName ("A7:B192") oColumnColumn = oSheet.getCellRangeByName ("A7:A192")
subReportChi2GoodnessOfFit (oDoc, oRange) oRowColumn = oSheet.getCellRangeByName ("B7:B192")
subReportChi2GoodnessOfFit (oDoc, oColumnColumn, oRowColumn)
End Sub End Sub
' subReportChi2GoodnessOfFit: Reports the chi-square goodness of fit ' subReportChi2GoodnessOfFit: Reports the chi-square goodness of fit
Sub subReportChi2GoodnessOfFit (oDoc As Object, oDataRange As Object) Sub subReportChi2GoodnessOfFit (oDoc As Object, oColumnColumn As Object, oRowColumn As Object)
Dim oSheets As Object, sSheetName As String Dim oSheets As Object, sSheetName As String
Dim nI As Integer, nJ As Integer, nJ1 As Integer, nJ2 As Integer Dim nI As Integer, nJ As Integer, nJ1 As Integer, nJ2 As Integer
Dim mNames () As String, nSheetIndex As Integer Dim mNames () As String, nSheetIndex As Integer
@ -54,7 +210,7 @@ Sub subReportChi2GoodnessOfFit (oDoc As Object, oDataRange As Object)
Dim sSE2 AS String, nTotalColumns As Integer Dim sSE2 AS String, nTotalColumns As Integer
oSheets = oDoc.getSheets oSheets = oDoc.getSheets
sSheetName = oDataRange.getSpreadsheet.getName sSheetName = oColumnColumn.getSpreadsheet.getName
mNames = oSheets.getElementNames mNames = oSheets.getElementNames
For nI = 0 To UBound (mNames) For nI = 0 To UBound (mNames)
If mNames (nI) = sSheetName Then If mNames (nI) = sSheetName Then
@ -64,21 +220,21 @@ Sub subReportChi2GoodnessOfFit (oDoc As Object, oDataRange As Object)
oSheets.insertNewByName (sSheetName & "_chi2", nSheetIndex + 1) oSheets.insertNewByName (sSheetName & "_chi2", nSheetIndex + 1)
oSheet = oSheets.getByName (sSheetName & "_chi2") oSheet = oSheets.getByName (sSheetName & "_chi2")
sCellsJData = fnGetRangeName (oDataRange.getCellRangeByPosition (0, 1, 0, oDataRange.getRows.getCount - 1)) sCellsJData = fnGetRangeName (oColumnColumn.getCellRangeByPosition (0, 1, 0, oColumnColumn.getRows.getCount - 1))
sCellsIData = fnGetRangeName (oDataRange.getCellRangeByPosition (1, 1, 1, oDataRange.getRows.getCount - 1)) sCellsIData = fnGetRangeName (oRowColumn.getCellRangeByPosition (0, 1, 0, oRowColumn.getRows.getCount - 1))
' Counts the number of groups and events ' Counts the number of groups and events
sLabelsColumn = " " sLabelsColumn = " "
sLabelsRow = " " sLabelsRow = " "
nGroups = 0 nGroups = 0
nEvents = 0 nEvents = 0
For nRow = 1 To oDataRange.getRows.getCount - 1 For nRow = 1 To oColumnColumn.getRows.getCount - 1
sLabel = oDataRange.getCellByPosition (0, nRow).getString sLabel = oColumnColumn.getCellByPosition (0, nRow).getString
If InStr (sLabelsColumn, " " & sLabel & " ") = 0 Then If InStr (sLabelsColumn, " " & sLabel & " ") = 0 Then
sLabelsColumn = sLabelsColumn & sLabel & " " sLabelsColumn = sLabelsColumn & sLabel & " "
nGroups = nGroups + 1 nGroups = nGroups + 1
End If End If
sLabel = oDataRange.getCellByPosition (1, nRow).getString sLabel = oRowColumn.getCellByPosition (0, nRow).getString
If InStr (sLabelsRow, " " & sLabel & " ") = 0 Then If InStr (sLabelsRow, " " & sLabel & " ") = 0 Then
sLabelsRow = sLabelsRow & sLabel & " " sLabelsRow = sLabelsRow & sLabel & " "
nEvents = nEvents + 1 nEvents = nEvents + 1
@ -96,15 +252,15 @@ Sub subReportChi2GoodnessOfFit (oDoc As Object, oDataRange As Object)
sLabelsRow = " " sLabelsRow = " "
nJ = 0 nJ = 0
nI = 0 nI = 0
For nRow = 1 To oDataRange.getRows.getCount - 1 For nRow = 1 To oColumnColumn.getRows.getCount - 1
oCell = oDataRange.getCellByPosition (0, nRow) oCell = oColumnColumn.getCellByPosition (0, nRow)
sLabel = oCell.getString sLabel = oCell.getString
If InStr (sLabelsColumn, " " & sLabel & " ") = 0 Then If InStr (sLabelsColumn, " " & sLabel & " ") = 0 Then
sLabelsColumn = sLabelsColumn & sLabel & " " sLabelsColumn = sLabelsColumn & sLabel & " "
mCellLabelColomn (nJ) = fnGetRangeName (oCell) mCellLabelColomn (nJ) = fnGetRangeName (oCell)
nJ = nJ + 1 nJ = nJ + 1
End If End If
oCell = oDataRange.getCellByPosition (1, nRow) oCell = oRowColumn.getCellByPosition (0, nRow)
sLabel = oCell.getString sLabel = oCell.getString
If InStr (sLabelsRow, " " & sLabel & " ") = 0 Then If InStr (sLabelsRow, " " & sLabel & " ") = 0 Then
sLabelsRow = sLabelsRow & sLabel & " " sLabelsRow = sLabelsRow & sLabel & " "