[Solved] Function in Basic

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
karonte
Posts: 2
Joined: Sun Sep 21, 2008 10:28 am

[Solved] Function in Basic

Post by karonte »

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

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
User avatar
squenson
Volunteer
Posts: 1885
Joined: Wed Jan 30, 2008 9:21 pm
Location: Lausanne, Switzerland

Re: Function in Basic

Post by squenson »

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

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
karonte
Posts: 2
Joined: Sun Sep 21, 2008 10:28 am

Re: Function in Basic

Post by karonte »

Thank you very much, squenson, this is what I was looking for.
OOo 2.4.X on openSuse 11 + XP
Post Reply