[Solved] Function in Basic

The Application Programming Interface and the OASIS Open Document Format

[Solved] Function in Basic

Postby karonte » Sun Sep 21, 2008 10:35 am

Hello
First excuse me if this is not the correct forum for this question. I need to write some Basic code, my previous experience is with Excel only. In Excel I have some code like this:

Code: Select all   Expand viewCollapse view
Function A(B)
  ' b is a parameter in my Basic function.
  A = NormSDist(B)
End Function


How can I do this in OO Basic? (I receive an error: Function procedure not defined).
I must load a library? Can you please write how can I do it?

Thank you very much.
Last edited by karonte on Sun Sep 21, 2008 12:47 pm, edited 1 time in total.
OOo 2.4.X on openSuse 11 + XP
karonte
 
Posts: 2
Joined: Sun Sep 21, 2008 10:28 am

Re: Function in Basic

Postby squenson » Sun Sep 21, 2008 12:33 pm

Here is some code for the function NORMDIST, which is more or less equivalent to NormSDist in Excel (look at the help file, it takes four parameters):
Code: Select all   Expand viewCollapse view
Function ReturnNormDist(b)
   
                     ' Create the service that allows to use
                     ' a Calc function in a macro
   Dim oFunction as Object
   oFunction = createUnoService("com.sun.star.sheet.FunctionAccess")
   
                     ' The function NORMDIST() takes four arguments
                     ' in Calc, therefore we need to create an array
                     ' of this size and pre-fill three arguments
   Dim args( 1 to 4 ) As Variant
   args(1) = b
   args(2) = 0
   args(3) = 1
   args(4) = 1

                     ' We call the Calc function this way
   ReturnNormDist = oFunction.callFunction("NORMDIST", args())
   
End Function
LibreOffice 4.2.3.3. on Ubuntu 14.04
User avatar
squenson
Volunteer
 
Posts: 1885
Joined: Wed Jan 30, 2008 9:21 pm
Location: Lausanne, Switzerland

Re: Function in Basic

Postby karonte » Sun Sep 21, 2008 12:42 pm

Thank you very much, squenson, this is what I was looking for.
OOo 2.4.X on openSuse 11 + XP
karonte
 
Posts: 2
Joined: Sun Sep 21, 2008 10:28 am


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 1 guest