[Solved] Error in arguments, built in function

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
amiltonpueljr
Posts: 26
Joined: Mon Sep 03, 2012 1:53 am

[Solved] Error in arguments, built in function

Post by amiltonpueljr »

Well, it works, but not what I really need.

Code: Select all

 Sub regressao

       svc = createUnoService( "com.sun.star.sheet.FunctionAccess" )
       
    dim rend ( 1 to 3 ) as double
    dim y ( 1 to 3 ) as double
    dim coef as double
    
       oDoc = thisComponent
      oForm2 = oDoc.DrawPage.Forms.getByName("MainForm").getbyname("SubForm").getbyname("gridace")
      rend(1) = oForm2.RowSet.Columns.getbyname("Rend50").value
      rend(2) = oForm2.RowSet.Columns.getbyname("Rend75").value
      rend(3) = oForm2.RowSet.Columns.getbyname("Rend100").value
      
      y(1) = 0.5
      y(2) = 0.75
      y(3) = 1
       
    result = svc.callFunction( "LINEST", y, rend )

End Sub
The error is: ::com::sun::star::lang::IllegalArgumentException, wich I know what it means but can't fix it.
The result if doing in calc would be something like this(CTRL + SHIFT + ENTER):

2090,531693 2715,334385

570,8920868 863,3916473
0,770237485 1041,892876
13,40928019 4
14556320,27 4342163,06
And then I'm going to commit those two bolded values to a table for further calculations
Last edited by amiltonpueljr on Sat Feb 23, 2013 11:29 pm, edited 1 time in total.
Trying to learns base basics or not so basics
OpenOffice 3.5.6 on Windows 7 Home Premium
FJCC
Moderator
Posts: 9615
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Error in arguments, built in function

Post by FJCC »

Linest() is expecting two dimensional arrays, I suppose because cell ranges are structured as two dimensional arrays. Also, the arguments have to be passed as an array. Try something like this:

Code: Select all

   svc = createUnoService( "com.sun.star.sheet.FunctionAccess" )
       
    dim rend ( 2 ,0) as double
    dim y ( 2 ,0) as double
    dim coef as double
   
       oDoc = thisComponent
      
      oForm2 = oDoc.DrawPage.Forms.getByName("MainForm").getbyname("SubForm").getbyname("gridace")
      rend(0,0) = oForm2.RowSet.Columns.getbyname("Rend50").value
      rend(1,0) = oForm2.RowSet.Columns.getbyname("Rend75").value
      rend(2,0) = oForm2.RowSet.Columns.getbyname("Rend100").value
     
      y(0,0) = 0.5
      y(1,0) = 0.75
      y(2,0) = 1
    
    result = svc.callFunction( "LINEST", Array(y, rend ))
    print result(0)(0), result(0)(1)
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
amiltonpueljr
Posts: 26
Joined: Mon Sep 03, 2012 1:53 am

Re: Error in arguments, built in function

Post by amiltonpueljr »

Hey man,

That worked exactly how I needed it !

Thanks a lot
Trying to learns base basics or not so basics
OpenOffice 3.5.6 on Windows 7 Home Premium
Post Reply