| View previous topic :: View next topic |
| Author |
Message |
Timurlang General User

Joined: 30 Nov 2011 Posts: 8
|
Posted: Wed Nov 30, 2011 11:32 am Post subject: Size of functions |
|
|
Hi,
I must calculate the standard deviation of an array.
Easy:
svc = createUnoService( "com.sun.star.sheet.FunctionAccess" )
STD = svc.callfunction ("STDEVP", MyArray())
that is, it works as long as the array is small (is 256 the max?)
How can I solve the problem with a larger (270 elements) array? |
|
| Back to top |
|
 |
keme Moderator


Joined: 30 Aug 2004 Posts: 2732 Location: Egersund, Norway
|
Posted: Wed Nov 30, 2011 11:08 pm Post subject: |
|
|
Not sure how StarBasic handles this, but just a thought:
Did you explicitly DIM your MyArray variable to be large enough for your data?
It may well be that implicit array declarations limits size to 256 elements. |
|
| Back to top |
|
 |
Timurlang General User

Joined: 30 Nov 2011 Posts: 8
|
Posted: Thu Dec 01, 2011 1:37 am Post subject: |
|
|
Yes I did.
Dim MyArray(500) as double 'made a larger then needed array
n = 270 ' number of elements
Redim Preserve MyArray(n - 1) as double 'resizing the arrray once filled and the number of 'elements is known
By the way, I'm using Calc OO3.3.
I think I can calculate the standard deviation by writing a function but I was wondering if I could somehow use the built-in one. |
|
| Back to top |
|
 |
B Marcelly Super User

Joined: 12 May 2004 Posts: 1414 Location: France
|
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Thu Dec 01, 2011 11:01 pm Post subject: |
|
|
Hi,
Try like as follows: | Code: | Sub FunctionAccessWithLargeArray
Dim b(253) As Double
Dim c(253) As Double
For i = 0 to 253 step 1
b(i) = i
c(i) = i + 254
Next
a = Array(b, c)
oFa = CreateUnoService("com.sun.star.sheet.FunctionAccess")
r = oFa.callFunction("MAX", Array(a))
msgbox r
End Sub |
|
|
| Back to top |
|
 |
Timurlang General User

Joined: 30 Nov 2011 Posts: 8
|
Posted: Sat Dec 17, 2011 10:15 am Post subject: |
|
|
Hi Hanya
Sorry for the late reply, but I had more pressing issues and could not test your solution till today.
It worked like a charm.
Thank you very much |
|
| Back to top |
|
 |
B Marcelly Super User

Joined: 12 May 2004 Posts: 1414 Location: France
|
Posted: Sun Dec 18, 2011 12:07 am Post subject: |
|
|
Hi,
Hanya's solution is food for thought
It works because it complies with the syntax for the second argument of callFunction :
| Developer's Guide wrote: | | The second parameter to callFunction() is a sequence containing the function arguments. The supported types for each argument are described in the com.sun.star.sheet.XFunctionAccess interface description (...) In Calc, an argument of the function may accept a range of cells, e.g =SUM(B12:G55). When calling a spreadsheet function, a range argument is transmitted as an array with two dimensions. The first corresponds to the row, the second corresponds to the column, indexes are zero-based. |
On the contrary, the initial code does not comply with the syntax for callFunction :
| Code: | svc = createUnoService( "com.sun.star.sheet.FunctionAccess" )
STD = svc.callfunction ("STDEVP", MyArray())
' where myArray() is the list of values |
The above code only works "by accident". And only with less than 255 values.
If your argument is a list of values you should think of them as a column of values in a Calc sheet. Then you should write for example :
| Code: | Sub OneArgWithManyValues
Dim fa As Object, r As Double, y As Long
Dim argList(0) As Variant ' one argument for this function
Dim arg1(3000, 0) As Double ' 3001 values for this argument
' filling the array
for y = 0 to UBound(arg1, 1)
arg1(y,0) = y*y*y -133*y*y -7000*y +556.4
next
' calling the Calc function
fa = CreateUnoService("com.sun.star.sheet.FunctionAccess"
argList(0) = arg1 ' one argument : the list of values
r = fa.callFunction("MEDIAN", argList )
msgbox r
End Sub
|
The maximum number of values acceptable is limited by the maximum number of columns and rows in a Calc sheet. This depends on the version of OpenOffice.org. With OOo 3.3 or LibreOffice 3.4.2, a single column can have up to 1048376 values. _________________ Bernard
OpenOffice.org 1.1.5 fr / OpenOffice.org 3.4.1 en-US + langpacks, MS-Windows XP Home SP3
This forum is unusable, use instead Apache OpenOffice forums |
|
| Back to top |
|
 |
|