Calling a built-in function

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
rmcd
Posts: 10
Joined: Thu Dec 06, 2007 8:00 pm

Calling a built-in function

Post by rmcd »

I'm trying to call built-in functions (as in Excel VBA) and can't get it to work. Based on examples I gather I need to do something like this:

Function calc_Func(sFunc$,args())
dim oFA as Object
oFA = createUNOService("com.sun.star.sheet.FunctionAccess")
calc_Func = oFA.callFunction(sFunc,args())
end function

Function test(x as double) as double
test =calc_Func("NORMSDIST",x())
End Function

However, when I call test(0.5) I get "Basic runtime error. Object variable not set." with the arrow pointing to the line "calc_func = ofa.callFunction".

How does this work? Thanks.

Bob
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Calling a built-in function

Post by B Marcelly »

Hi,
You must transmit an array of argument(s)

Code: Select all

test =calc_Func("NORMSDIST", Array(x))
______
Bernard
rmcd
Posts: 10
Joined: Thu Dec 06, 2007 8:00 pm

Re: Calling a built-in function

Post by rmcd »

Thanks very much!

Since I had trouble finding a *simple* working example, I will post my working test cases. I hope if there is anything wrong or misleading here someone will correct me.

Function calc_Func(sFunc$,args())
dim oFA as Object
oFA = createUNOService("com.sun.star.sheet.FunctionAccess")
calc_Func = oFA.callFunction(sFunc,args())
end function

' a function with one parameter
Function test(x) as double
test =calc_Func("NORMSDIST",array(x))
End Function

' a function with three parameters
Function test2(xval as double,mu as double,sig as double) as double
test2=calc_Func("STANDARDIZE",Array(xval,mu,sig))
end function
Post Reply