Renamed the modules for extension publishing. Changed to use dialogs instead of code-created dialogs for localized UI.

This commit is contained in:
依瑪貓 2016-09-08 16:23:24 +08:00
parent 4816c5250d
commit 3ddf7f2d42
6 changed files with 117 additions and 710 deletions

View File

@ -1,4 +1,4 @@
' _1CorRel: The macros to for generating the report of the Pearsons correlation coefficient
' 1CorRel: The macros to for generating the report of the Pearsons correlation coefficient
' by imacat <imacat@mail.imacat.idv.tw>, 2016-08-10
Option Explicit
@ -6,151 +6,39 @@ 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
Dim oSheets As Object, sSheetName As String
Dim oSheet As Object, mRanges As Object
Dim sExisted As String, nResult As Integer
' 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
' Specifies the data
mRanges = fnSpecifyData (oRange, _
"&3.Dlg2SpecData.txtPrompt1.Label1CorRel", _
"&6.Dlg2SpecData.txtPrompt2.Label1CorRel")
If IsNull (mRanges) 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 = ""
sSheetName = oRange.getSpreadsheet.getName
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
sExisted = "Spreadsheet """ & sSheetName & "_correl"" exists. Overwrite?"
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
oSheets.removeByname (sSheetName & "_correl")
End If
' Reports the paired T-test.
subReportCorrelation (ThisComponent, oRange1, oRange2)
subReportCorrelation (ThisComponent, mRanges (0), mRanges (1))
' Makes the report sheet active.
oSheet = oSheets.getByName (sSheetName & "_correl")

View File

@ -1,4 +1,4 @@
' _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
Option Explicit
@ -6,151 +6,39 @@ 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
Dim oSheets As Object, sSheetName As String
Dim oSheet As Object, mRanges As Object
Dim sExisted As String, nResult As Integer
' 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
' Specifies the data
mRanges = fnSpecifyData (oRange, _
"&3.Dlg2SpecData.txtPrompt1.Label1CorRel", _
"&6.Dlg2SpecData.txtPrompt2.Label1CorRel")
If IsNull (mRanges) 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 = ""
sSheetName = oRange.getSpreadsheet.getName
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
sExisted = "Spreadsheet """ & sSheetName & "_ttest"" exists. Overwrite?"
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
oSheets.removeByname (sSheetName & "_ttest")
End If
' Reports the paired T-test.
subReportPairedTTest (ThisComponent, oRange1, oRange2)
subReportPairedTTest (ThisComponent, mRanges (0), mRanges (1))
' Makes the report sheet active.
oSheet = oSheets.getByName (sSheetName & "_ttest")

View File

@ -1,4 +1,4 @@
' _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
Option Explicit
@ -6,127 +6,27 @@ Option Explicit
' 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
Dim oSheets As Object, sSheetName As String
Dim oSheet As Object, mRanges As Object
Dim sExisted As String, nResult As Integer
' 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
' Specifies the data
mRanges = fnSpecifyData (oRange, _
"&10.Dlg2SpecData.txtPrompt1.Label3ITTest", _
"&11.Dlg2SpecData.txtPrompt2.Label3ITTest")
If IsNull (mRanges) 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
sSheetName = oRange.getSpreadsheet.getName
sExisted = ""
If oSheets.hasByName (sSheetName & "_ttest") Then
sExisted = sExisted & ", """ & sSheetName & "_ttest"""
@ -145,7 +45,6 @@ Sub subRunIndependentTTest As Object
If nResult = IDNO Then
Exit Sub
End If
' Drops the existing report
If oSheets.hasByName (sSheetName & "_ttest") Then
oSheets.removeByname (sSheetName & "_ttest")
@ -156,7 +55,7 @@ Sub subRunIndependentTTest As Object
End If
' Reports the independent T-test.
subReportIndependentTTest (ThisComponent, oRange1, oRange2)
subReportIndependentTTest (ThisComponent, mRanges (0), mRanges (1))
' Makes the report sheet active.
oSheet = oSheets.getByName (sSheetName & "_ttest")

View File

@ -1,4 +1,4 @@
' _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
Option Explicit
@ -6,127 +6,27 @@ 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
Dim oSheets As Object, sSheetName As String
Dim oSheet As Object, mRanges As Object
Dim sExisted As String, nResult As Integer
' 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
' Specifies the data
mRanges = fnSpecifyData (oRange, _
"&10.Dlg2SpecData.txtPrompt1.Label3ITTest", _
"&11.Dlg2SpecData.txtPrompt2.Label3ITTest")
If IsNull (mRanges) 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
sSheetName = oRange.getSpreadsheet.getName
sExisted = ""
If oSheets.hasByName (sSheetName & "_anova") Then
sExisted = sExisted & ", """ & sSheetName & "_anova"""
@ -145,7 +45,6 @@ Sub subRunANOVA As Object
If nResult = IDNO Then
Exit Sub
End If
' Drops the existing report
If oSheets.hasByName (sSheetName & "_anova") Then
oSheets.removeByname (sSheetName & "_anova")
@ -156,7 +55,7 @@ Sub subRunANOVA As Object
End If
' Reports the ANOVA (Analyze of Variances)
subReportANOVA (ThisComponent, oRange1, oRange2)
subReportANOVA (ThisComponent, mRanges (0), mRanges (1))
' Makes the report sheet active.
oSheet = oSheets.getByName (sSheetName & "_anova")

View File

@ -1,4 +1,4 @@
' _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
Option Explicit
@ -6,151 +6,39 @@ 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
Dim oSheets As Object, sSheetName As String
Dim oSheet As Object, mRanges As Object
Dim sExisted As String, nResult As Integer
' 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
' Specifies the data
mRanges = fnSpecifyData (oRange, _
"&12.Dlg2SpecData.txtPrompt1.Label5Chi2GoF", _
"&13.Dlg2SpecData.txtPrompt2.Label5Chi2GoF")
If IsNull (mRanges) 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 = ""
sSheetName = oRange.getSpreadsheet.getName
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
sExisted = "Spreadsheet """ & sSheetName & "_chi2"" exists. Overwrite?"
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
oSheets.removeByname (sSheetName & "_chi2")
End If
' Reports the chi-square goodness of fit
subReportChi2GoodnessOfFit (ThisComponent, oRange1, oRange2)
subReportChi2GoodnessOfFit (ThisComponent, mRanges (0), mRanges (1))
' Makes the report sheet active.
oSheet = oSheets.getByName (sSheetName & "_chi2")

View File

@ -1,23 +1,12 @@
' _0Main: The main module for the statistics macros
' 9Tools: The tool macros
' by imacat <imacat@mail.imacat.idv.tw>, 2016-08-10
Option Explicit
' subMain: The main program
Sub subMain
Sub subTest
BasicLibraries.loadLibrary "XrayTool"
subRunCorrelation
'subRunPairedTTest
'subRunIndependentTTest
'subRunAnova
'subRunChi2GoodnessOfFit
'subTestCorrelation
'subTestPairedTTest
'subTestIndependentTTest
'subTestANOVA
'subTestChi2GoodnessOfFit
MsgBox fnFormatString ("abc % def", Array ("ghi"))
End Sub
' fnCheckRangeName: Checks the range name and returns the range when
@ -100,51 +89,56 @@ Function fnFindStatsTestDocument As Object
Loop
End Function
' fnSpecifyData: Specifies the data
Function fnSpecifyData (oRange As Object, sPrompt1 As String, sPrompt2 As String) As Object
Dim mLabels (oRange.getColumns.getCount - 1) As String
Dim nI As Integer, mSelected (0) As Integer
Dim oDialog As Object, oTextModel As Object
Dim oListModel1 As object, oListModel2 As Object
Dim nResult As Integer, nColumn As Integer, mRanges (1) As Object
For nI = 0 To oRange.getColumns.getCount - 1
mLabels (nI) = oRange.getCellByPosition (nI, 0).getString
Next nI
' Runs the dialog
oDialog = CreateUnoDialog (DialogLibraries.Stats.Dlg2SpecData)
oTextModel = oDialog.getControl ("txtPrompt1").getModel
oTextModel.setPropertyValue ("Label", sPrompt1)
oListModel1 = oDialog.getControl ("lstData1").getModel
oListModel1.setPropertyValue ("StringItemList", mLabels)
mSelected (0) = 0
oListModel1.setPropertyValue ("SelectedItems", mSelected)
oTextModel = oDialog.getControl ("txtPrompt2").getModel
oTextModel.setPropertyValue ("Label", sPrompt2)
oListModel2 = oDialog.getControl ("lstData2").getModel
oListModel2.setPropertyValue ("StringItemList", mLabels)
mSelected (0) = 1
oListModel2.setPropertyValue ("SelectedItems", mSelected)
nResult = oDialog.execute
oDialog.dispose
' Cancelled
If nResult = 0 Then
Exit Function
End If
nColumn = oListModel1.getPropertyValue ("SelectedItems") (0)
mRanges (0) = oRange.getCellRangeByPosition ( _
nColumn, 0, nColumn, oRange.getRows.getCount - 1)
nColumn = oListModel2.getPropertyValue ("SelectedItems") (0)
mRanges (1) = oRange.getCellRangeByPosition ( _
nColumn, 0, nColumn, oRange.getRows.getCount - 1)
fnSpecifyData = mRanges
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 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)
@ -153,66 +147,17 @@ Function fnAskDataRange2 (oDoc As Object) As Object
Else
sCellsData = oRange.getPropertyValue ("AbsoluteName")
End If
sPrompt = "Cells with the data:"
sPrompt = "&27.Dlg1AskRange.txtPrompt.Label"
' 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)
' Runs the dialog
oDialog = CreateUnoDialog (DialogLibraries.Stats.Dlg1AskRange)
oTextModel = oDialog.getControl ("txtPrompt").getModel
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 = oDialog.getControl ("edtCellsData").getModel
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
@ -223,14 +168,14 @@ Function fnAskDataRange2 (oDoc As Object) As Object
sCellsData = oEditModel.getPropertyValue ("Text")
If sCellsData = "" Then
sPrompt = "Cells with the data:"
sPrompt = "&27.Dlg1AskRange.txtPrompt.Label"
Else
oRange = fnCheckRangeName (oDoc, sCellsData)
If IsNull (oRange) Then
sPrompt = "The range """ & sCellsData & """ does not exist."
sPrompt = "&35.Dlg1AskRange.txtPrompt.LabelNotExists"
Else
If oRange.getRows.getCount < 2 Or oRange.getColumns.getCount < 2 Then
sPrompt = "The range """ & sCellsData & """ is too small (at least 2×2)."
sPrompt = "&36.Dlg1AskRange.txtPrompt.LabelTooSmall"
Else
sPrompt = ""
oDoc.getCurrentController.select (oRange)