Ask LibreOffice - RSS feedhttps://ask.libreoffice.org/en/questions/Questions and answers for LibreOfficeenTue, 19 Jul 2016 23:38:01 +0200How to use math functions in the Calc Basic?https://ask.libreoffice.org/en/question/73551/how-to-use-math-functions-in-the-calc-basic/The documentations [shows](https://help.libreoffice.org/Calc/User-Defined_Functions#Defining_A_Function_Using_LibreOffice_Basic) how to implement a basic VOL function:
Function VOL(a, b, c)
VOL = a*b*c
End Function
So that I can write
=VOL(1,2,3)
in a spreadsheet and get 6.
I want to write `arctan` which would return result in degrees instead of radians:
Function ARCTAN(rad)
ARCTAN = ATAN(rad)*180/PI()
End Function
and call it as, e.g.:
=ARCTAN(1)
This doesn't work: Calc complains:
> Sub-procedure or function procedure not defined
Can you help me to write this function?
Tue, 19 Jul 2016 18:15:03 +0200https://ask.libreoffice.org/en/question/73551/how-to-use-math-functions-in-the-calc-basic/Answer by peterwt for <p>The documentations <a href="https://help.libreoffice.org/Calc/User-Defined_Functions#Defining_A_Function_Using_LibreOffice_Basic">shows</a> how to implement a basic VOL function:</p>
<pre><code>Function VOL(a, b, c)
VOL = a*b*c
End Function
</code></pre>
<p>So that I can write</p>
<pre><code>=VOL(1,2,3)
</code></pre>
<p>in a spreadsheet and get 6.</p>
<p>I want to write <code>arctan</code> which would return result in degrees instead of radians:</p>
<pre><code>Function ARCTAN(rad)
ARCTAN = ATAN(rad)*180/PI()
End Function
</code></pre>
<p>and call it as, e.g.:</p>
<pre><code>=ARCTAN(1)
</code></pre>
<p>This doesn't work: Calc complains:</p>
<blockquote>
<p>Sub-procedure or function procedure not defined</p>
</blockquote>
<p>Can you help me to write this function?</p>
https://ask.libreoffice.org/en/question/73551/how-to-use-math-functions-in-the-calc-basic/?answer=73556#post-id-73556See posting [here](https://ask.libreoffice.org/en/question/28048/can-we-use-regular-spreadsheet-functions-in-basic-functions/).<br>
Tue, 19 Jul 2016 19:06:52 +0200https://ask.libreoffice.org/en/question/73551/how-to-use-math-functions-in-the-calc-basic/?answer=73556#post-id-73556Comment by Adobe for <p>See posting <a href="https://ask.libreoffice.org/en/question/28048/can-we-use-regular-spreadsheet-functions-in-basic-functions/">here</a>.<br></p>
https://ask.libreoffice.org/en/question/73551/how-to-use-math-functions-in-the-calc-basic/?comment=73583#post-id-73583Thanks. The example you linked is more of a [currying])(https://en.wikipedia.org/wiki/Currying) though.Tue, 19 Jul 2016 23:20:33 +0200https://ask.libreoffice.org/en/question/73551/how-to-use-math-functions-in-the-calc-basic/?comment=73583#post-id-73583Answer by Ratslinger for <p>The documentations <a href="https://help.libreoffice.org/Calc/User-Defined_Functions#Defining_A_Function_Using_LibreOffice_Basic">shows</a> how to implement a basic VOL function:</p>
<pre><code>Function VOL(a, b, c)
VOL = a*b*c
End Function
</code></pre>
<p>So that I can write</p>
<pre><code>=VOL(1,2,3)
</code></pre>
<p>in a spreadsheet and get 6.</p>
<p>I want to write <code>arctan</code> which would return result in degrees instead of radians:</p>
<pre><code>Function ARCTAN(rad)
ARCTAN = ATAN(rad)*180/PI()
End Function
</code></pre>
<p>and call it as, e.g.:</p>
<pre><code>=ARCTAN(1)
</code></pre>
<p>This doesn't work: Calc complains:</p>
<blockquote>
<p>Sub-procedure or function procedure not defined</p>
</blockquote>
<p>Can you help me to write this function?</p>
https://ask.libreoffice.org/en/question/73551/how-to-use-math-functions-in-the-calc-basic/?answer=73581#post-id-73581
function ARCTAN(rad as double) as double
ARCTAN = atn(rad)*180/PI()
End Function
does work in LO v5.1.3.2 the only difference from original question being atn() vs ATAN() and this thanks to @Regina.
Also in this versions' off line Help, start with `Content` tab then `Macros and Programming`, `Command Reference` and finally `Alphabetic List of Functions, Statements and Operators`
Pi is actually used in the help example.Tue, 19 Jul 2016 23:11:02 +0200https://ask.libreoffice.org/en/question/73551/how-to-use-math-functions-in-the-calc-basic/?answer=73581#post-id-73581Answer by Regina for <p>The documentations <a href="https://help.libreoffice.org/Calc/User-Defined_Functions#Defining_A_Function_Using_LibreOffice_Basic">shows</a> how to implement a basic VOL function:</p>
<pre><code>Function VOL(a, b, c)
VOL = a*b*c
End Function
</code></pre>
<p>So that I can write</p>
<pre><code>=VOL(1,2,3)
</code></pre>
<p>in a spreadsheet and get 6.</p>
<p>I want to write <code>arctan</code> which would return result in degrees instead of radians:</p>
<pre><code>Function ARCTAN(rad)
ARCTAN = ATAN(rad)*180/PI()
End Function
</code></pre>
<p>and call it as, e.g.:</p>
<pre><code>=ARCTAN(1)
</code></pre>
<p>This doesn't work: Calc complains:</p>
<blockquote>
<p>Sub-procedure or function procedure not defined</p>
</blockquote>
<p>Can you help me to write this function?</p>
https://ask.libreoffice.org/en/question/73551/how-to-use-math-functions-in-the-calc-basic/?answer=73566#post-id-73566In this special case, you can use the internal functions of Basic. For a list of these functions see `Alphabetic List of Functions, Statements and Operators` in section `Command Reference` in tab `Contents` of the Help.
Your function might read
function ARCTAN(rad as double) as double
ARCTAN = atn(rad)*45.0/atn(1)
end function
You need 45.0/atn(1) instead of 180.0/PI(), because PI() is not available as Basic-internal function.Tue, 19 Jul 2016 20:49:26 +0200https://ask.libreoffice.org/en/question/73551/how-to-use-math-functions-in-the-calc-basic/?answer=73566#post-id-73566Comment by Adobe for <p>In this special case, you can use the internal functions of Basic. For a list of these functions see <code>Alphabetic List of Functions, Statements and Operators</code> in section <code>Command Reference</code> in tab <code>Contents</code> of the Help.</p>
<p>Your function might read</p>
<pre><code>function ARCTAN(rad as double) as double
ARCTAN = atn(rad)*45.0/atn(1)
end function
</code></pre>
<p>You need 45.0/atn(1) instead of 180.0/PI(), because PI() is not available as Basic-internal function.</p>
https://ask.libreoffice.org/en/question/73551/how-to-use-math-functions-in-the-calc-basic/?comment=73577#post-id-73577`PI()` is not available but `Pi` works: `ARCTAN = atn(rad) * 180 / Pi`. Thanks!Tue, 19 Jul 2016 22:50:53 +0200https://ask.libreoffice.org/en/question/73551/how-to-use-math-functions-in-the-calc-basic/?comment=73577#post-id-73577Comment by Ratslinger for <p>In this special case, you can use the internal functions of Basic. For a list of these functions see <code>Alphabetic List of Functions, Statements and Operators</code> in section <code>Command Reference</code> in tab <code>Contents</code> of the Help.</p>
<p>Your function might read</p>
<pre><code>function ARCTAN(rad as double) as double
ARCTAN = atn(rad)*45.0/atn(1)
end function
</code></pre>
<p>You need 45.0/atn(1) instead of 180.0/PI(), because PI() is not available as Basic-internal function.</p>
https://ask.libreoffice.org/en/question/73551/how-to-use-math-functions-in-the-calc-basic/?comment=73584#post-id-73584Original function does work in LO v5.1.3.2 the only difference from original question being atn() vs ATAN() and this thanks to @Regina.
Also in this versions' off line Help, start with `Content` tab then `Macros and Programming`, `Command Reference` and finally `Alphabetic List of Functions, Statements and Operators`
Pi is actually used in the help example.
Changed "Answer' to "Comment" - posted just for Help reference.Tue, 19 Jul 2016 23:38:01 +0200https://ask.libreoffice.org/en/question/73551/how-to-use-math-functions-in-the-calc-basic/?comment=73584#post-id-73584Comment by Adobe for <p>In this special case, you can use the internal functions of Basic. For a list of these functions see <code>Alphabetic List of Functions, Statements and Operators</code> in section <code>Command Reference</code> in tab <code>Contents</code> of the Help.</p>
<p>Your function might read</p>
<pre><code>function ARCTAN(rad as double) as double
ARCTAN = atn(rad)*45.0/atn(1)
end function
</code></pre>
<p>You need 45.0/atn(1) instead of 180.0/PI(), because PI() is not available as Basic-internal function.</p>
https://ask.libreoffice.org/en/question/73551/how-to-use-math-functions-in-the-calc-basic/?comment=73582#post-id-73582Here's a list of most used math functions: `atn/sin/cos/tan/exp/log/sqr/abs` plus a constant `Pi`. [Source](https://help.libreoffice.org/Basic/Numeric_Functions).Tue, 19 Jul 2016 23:16:55 +0200https://ask.libreoffice.org/en/question/73551/how-to-use-math-functions-in-the-calc-basic/?comment=73582#post-id-73582