OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Size of functions

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Timurlang
General User
General User


Joined: 30 Nov 2011
Posts: 8

PostPosted: Wed Nov 30, 2011 11:32 am    Post subject: Size of functions Reply with quote

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
View user's profile Send private message
keme
Moderator
Moderator


Joined: 30 Aug 2004
Posts: 2732
Location: Egersund, Norway

PostPosted: Wed Nov 30, 2011 11:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
Timurlang
General User
General User


Joined: 30 Nov 2011
Posts: 8

PostPosted: Thu Dec 01, 2011 1:37 am    Post subject: Reply with quote

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
View user's profile Send private message
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1414
Location: France

PostPosted: Thu Dec 01, 2011 12:47 pm    Post subject: Reply with quote

Problem found in thread http://www.oooforum.org/forum/viewtopic.phtml?p=314408#314408
See Bug report 99348.
Not yet corrected, not even started. Evil or Very Mad
_________________
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
View user's profile Send private message Visit poster's website
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Thu Dec 01, 2011 11:01 pm    Post subject: Reply with quote

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
View user's profile Send private message
Timurlang
General User
General User


Joined: 30 Nov 2011
Posts: 8

PostPosted: Sat Dec 17, 2011 10:15 am    Post subject: Reply with quote

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
View user's profile Send private message
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1414
Location: France

PostPosted: Sun Dec 18, 2011 12:07 am    Post subject: Reply with quote

Hi,
Hanya's solution is food for thought Smile
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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group