Page 1 of 1

Calling a built-in function

Posted: Fri Dec 07, 2007 7:34 am
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

Re: Calling a built-in function

Posted: Fri Dec 07, 2007 9:05 am
by B Marcelly
Hi,
You must transmit an array of argument(s)

Code: Select all

test =calc_Func("NORMSDIST", Array(x))
______
Bernard

Re: Calling a built-in function

Posted: Sat Dec 08, 2007 1:21 am
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