From baa4275099b218c5db47501f48781f8adcef4321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Tue, 6 Sep 2016 21:19:35 +0800 Subject: [PATCH] Changed to find the statistics test document instead of using ThisComponent. --- _0Main.vb | 18 ++++++++++++++++++ _1CorRel.vb | 14 ++++++++++---- _2PTTest.vb | 14 ++++++++++---- _3ITTest.vb | 14 ++++++++++---- _4ANOVA.vb | 14 ++++++++++---- _5Chi2GoF.vb | 14 ++++++++++---- 6 files changed, 68 insertions(+), 20 deletions(-) diff --git a/_0Main.vb b/_0Main.vb index 1ddca66..cf3b5dd 100644 --- a/_0Main.vb +++ b/_0Main.vb @@ -12,6 +12,7 @@ Sub subMain 'MsgBox InStr (1, "abca", "ad") 'Xray ThisComponent.getSheets.getByIndex (0).getCellByPosition (0, 0) 'subTestCorrelation + subTestChi2GoodnessOfFit MsgBox "Done. " & Format (Now - dStart, "mm:ss") & " elapsed." End Sub @@ -54,3 +55,20 @@ Function fnGetLocalRangeName (oRange As Object) As String End If fnGetLocalRangeName = sName End Function + +' fnFindStatsTestDocument: Finds the statistics test document. +Function fnFindStatsTestDocument As Object + Dim oEnum As Object, oDoc As Object + + oEnum = StarDesktop.getComponents.createEnumeration + Do While oEnum.hasMoreElements + oDoc = oEnum.nextElement + If oDoc.supportsService ("com.sun.star.document.OfficeDocument") Then + If Right (oDoc.getLocation, Len ("/statstest.ods")) = "/statstest.ods" Then + fnFindStatsTestDocument = oDoc + Exit Function + End If + End If + Loop + fnFindStatsTestDocument = Null +End Function diff --git a/_1CorRel.vb b/_1CorRel.vb index 6891982..6e01ef6 100644 --- a/_1CorRel.vb +++ b/_1CorRel.vb @@ -5,11 +5,17 @@ Option Explicit ' subTestCorrelation: Tests the Pearson’s correlation coefficient report Sub subTestCorrelation - Dim oSheets As Object, sSheetName As String + Dim oDoc As Object, oSheets As Object, sSheetName As String Dim oSheet As Object, oRange As Object + oDoc = fnFindStatsTestDocument + If oDoc = Null Then + MsgBox "Cannot find statstest.ods in the opened documents." + Exit Sub + End If + sSheetName = "correl" - oSheets = ThisComponent.getSheets + oSheets = oDoc.getSheets If Not oSheets.hasByName (sSheetName) Then MsgBox "Data sheet """ & sSheetName & """ not found" Exit Sub @@ -17,9 +23,9 @@ Sub subTestCorrelation If oSheets.hasByName (sSheetName & "_correl") Then oSheets.removeByName (sSheetName & "_correl") End If - oSheet = ThisComponent.getSheets.getByName (sSheetName) + oSheet = oSheets.getByName (sSheetName) oRange = oSheet.getCellRangeByName ("B3:C13") - subReportCorrelation (ThisComponent, oRange) + subReportCorrelation (oDoc, oRange) End Sub ' subReportCorrelation: Reports the Pearson’s correlation coefficient diff --git a/_2PTTest.vb b/_2PTTest.vb index b191092..4e528c3 100644 --- a/_2PTTest.vb +++ b/_2PTTest.vb @@ -4,11 +4,17 @@ Option Explicit ' subTestPairedTTest: Tests the paired T-test report Sub subTestPairedTTest - Dim oSheets As Object, sSheetName As String + Dim oDoc As Object, oSheets As Object, sSheetName As String Dim oSheet As Object, oRange As Object + oDoc = fnFindStatsTestDocument + If oDoc = Null Then + MsgBox "Cannot find statstest.ods in the opened documents." + Exit Sub + End If + sSheetName = "pttest" - oSheets = ThisComponent.getSheets + oSheets = oDoc.getSheets If Not oSheets.hasByName (sSheetName) Then MsgBox "Data sheet """ & sSheetName & """ not found" Exit Sub @@ -16,9 +22,9 @@ Sub subTestPairedTTest If oSheets.hasByName (sSheetName & "_ttest") Then oSheets.removeByName (sSheetName & "_ttest") End If - oSheet = ThisComponent.getSheets.getByName (sSheetName) + oSheet = oSheets.getByName (sSheetName) oRange = oSheet.getCellRangeByName ("B3:C15") - subReportPairedTTest (ThisComponent, oRange) + subReportPairedTTest (oDoc, oRange) End Sub ' subReportPairedTTest: Reports the paired T-test diff --git a/_3ITTest.vb b/_3ITTest.vb index ba30198..327572a 100644 --- a/_3ITTest.vb +++ b/_3ITTest.vb @@ -4,11 +4,17 @@ Option Explicit ' subTestIndependentTTest: Tests the independent T-test report Sub subTestIndependentTTest - Dim oSheets As Object, sSheetName As String + Dim oDoc As Object, oSheets As Object, sSheetName As String Dim oSheet As Object, oRange As Object + oDoc = fnFindStatsTestDocument + If oDoc = Null Then + MsgBox "Cannot find statstest.ods in the opened documents." + Exit Sub + End If + sSheetName = "ittest" - oSheets = ThisComponent.getSheets + oSheets = oDoc.getSheets If Not oSheets.hasByName (sSheetName) Then MsgBox "Data sheet """ & sSheetName & """ not found" Exit Sub @@ -19,9 +25,9 @@ Sub subTestIndependentTTest If oSheets.hasByName (sSheetName & "_ttesttmp") Then oSheets.removeByName (sSheetName & "_ttesttmp") End If - oSheet = ThisComponent.getSheets.getByName (sSheetName) + oSheet = oSheets.getByName (sSheetName) oRange = oSheet.getCellRangeByName ("A15:B34") - subReportIndependentTTest (ThisComponent, oRange) + subReportIndependentTTest (oDoc, oRange) End Sub ' subReportIndependentTTest: Reports the independent T-test diff --git a/_4ANOVA.vb b/_4ANOVA.vb index 43de397..5497479 100644 --- a/_4ANOVA.vb +++ b/_4ANOVA.vb @@ -4,11 +4,17 @@ Option Explicit ' subTestANOVA: Tests the ANOVA (Analyze of Variances) report Sub subTestANOVA - Dim oSheets As Object, sSheetName As String + Dim oDoc As Object, oSheets As Object, sSheetName As String Dim oSheet As Object, oRange As Object + oDoc = fnFindStatsTestDocument + If oDoc = Null Then + MsgBox "Cannot find statstest.ods in the opened documents." + Exit Sub + End If + sSheetName = "anova" - oSheets = ThisComponent.getSheets + oSheets = oDoc.getSheets If Not oSheets.hasByName (sSheetName) Then MsgBox "Data sheet """ & sSheetName & """ not found" Exit Sub @@ -19,9 +25,9 @@ Sub subTestANOVA If oSheets.hasByName (sSheetName & "_anovatmp") Then oSheets.removeByName (sSheetName & "_anovatmp") End If - oSheet = ThisComponent.getSheets.getByName (sSheetName) + oSheet = oSheets.getByName (sSheetName) oRange = oSheet.getCellRangeByName ("A13:B35") - subReportANOVA (ThisComponent, oRange) + subReportANOVA (oDoc, oRange) End Sub ' subReportANOVA: Reports the ANOVA (Analyze of Variances) diff --git a/_5Chi2GoF.vb b/_5Chi2GoF.vb index 680088b..db1b90e 100644 --- a/_5Chi2GoF.vb +++ b/_5Chi2GoF.vb @@ -4,11 +4,17 @@ Option Explicit ' subTestChi2GoodnessOfFit: Tests the chi-square goodness of fit report Sub subTestChi2GoodnessOfFit - Dim oSheets As Object, sSheetName As String + Dim oDoc As Object, oSheets As Object, sSheetName As String Dim oSheet As Object, oRange As Object + oDoc = fnFindStatsTestDocument + If oDoc = Null Then + MsgBox "Cannot find statstest.ods in the opened documents." + Exit Sub + End If + sSheetName = "chi2" - oSheets = ThisComponent.getSheets + oSheets = oDoc.getSheets If Not oSheets.hasByName (sSheetName) Then MsgBox "Data sheet """ & sSheetName & """ not found" Exit Sub @@ -16,9 +22,9 @@ Sub subTestChi2GoodnessOfFit If oSheets.hasByName (sSheetName & "_chi2") Then oSheets.removeByName (sSheetName & "_chi2") End If - oSheet = ThisComponent.getSheets.getByName (sSheetName) + oSheet = oSheets.getByName (sSheetName) oRange = oSheet.getCellRangeByName ("A7:B192") - subReportChi2GoodnessOfFit (ThisComponent, oRange) + subReportChi2GoodnessOfFit (oDoc, oRange) End Sub ' subReportChi2GoodnessOfFit: Reports the chi-square goodness of fit