Page 1 of 1
[Solved] Call POWER function in StarBasic
Posted: Wed Jan 15, 2025 4:46 pm
by luofeiyu
To get "3^4" in the cell,you simply write "=power(3;4)".I want to call the power function in basic:
Code: Select all
sub test()
dim oFunctionAccess as object
dim aParameters(2) as integer
dim num as integer
oFunctionAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )
aParameters(0) = 3
aParameters(1) = 4
num = oFunctionAccess.CallFunction( "power", aParameters)
print num
end sub
It can't work,how to fix it?
Re: How to call power function in basic?
Posted: Wed Jan 15, 2025 5:02 pm
by Lupp
The POWER() function is superfluous anyway, because ther is the operator "^" for exponentiation.
does the trick.
BTW: The function and the operator as well also work with type Double.
Re: How to call power function in basic?
Posted: Wed Jan 15, 2025 5:04 pm
by luofeiyu
I want to call it with the format of `oFunctionAccess.CallFunction( "power",.....)`.
Re: How to call power function in basic?
Posted: Wed Jan 15, 2025 5:07 pm
by Lupp
That's a useless complication. Are there reasons?
Your error:
You dimensioned
and created an array with
three elements :(0), (1), (2): by that.
Re: Call POWER function in StarBasic
Posted: Thu Jan 16, 2025 2:50 am
by luofeiyu
The right format is as below:
Code: Select all
sub callpower()
dim oFunctionAccess as object
dim aParameters(1) as integer
dim num as integer
oFunctionAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )
aParameters(0) = 3
aParameters(1) = 4
num = oFunctionAccess.CallFunction( "power", aParameters)
print num
end sub
Re: [Solved] Call POWER function in StarBasic
Posted: Thu Jan 16, 2025 12:49 pm
by JeJe
Code: Select all
dim num
oFunctionAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )
num = oFunctionAccess.CallFunction( "power", array(3,4))
I presume you just want to learn how to use FunctionAccess as 3^4 is exactly the same - as Lupp and the help page says. Leaving num as a variant will prevent an overflow error with an integer if the return is large.
https://wiki.openoffice.org/wiki/Docume ... R_function