Changed to find the statistics test document instead of using ThisComponent.

This commit is contained in:
依瑪貓 2016-09-06 21:19:35 +08:00
parent e2e4dafeba
commit baa4275099
6 changed files with 68 additions and 20 deletions

View File

@ -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

View File

@ -5,11 +5,17 @@ Option Explicit
' subTestCorrelation: Tests the Pearsons 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 Pearsons correlation coefficient

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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