1*b1cdbd2cSJim Jagielski<?xml version="1.0" encoding="UTF-8"?>
2*b1cdbd2cSJim Jagielski
3*b1cdbd2cSJim Jagielski
4*b1cdbd2cSJim Jagielski<!--***********************************************************
5*b1cdbd2cSJim Jagielski *
6*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
7*b1cdbd2cSJim Jagielski * or more contributor license agreements.  See the NOTICE file
8*b1cdbd2cSJim Jagielski * distributed with this work for additional information
9*b1cdbd2cSJim Jagielski * regarding copyright ownership.  The ASF licenses this file
10*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
11*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
12*b1cdbd2cSJim Jagielski * with the License.  You may obtain a copy of the License at
13*b1cdbd2cSJim Jagielski *
14*b1cdbd2cSJim Jagielski *   http://www.apache.org/licenses/LICENSE-2.0
15*b1cdbd2cSJim Jagielski *
16*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
17*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
18*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19*b1cdbd2cSJim Jagielski * KIND, either express or implied.  See the License for the
20*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
21*b1cdbd2cSJim Jagielski * under the License.
22*b1cdbd2cSJim Jagielski *
23*b1cdbd2cSJim Jagielski ***********************************************************-->
24*b1cdbd2cSJim Jagielski
25*b1cdbd2cSJim Jagielski
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielski<helpdocument version="1.0">
28*b1cdbd2cSJim Jagielski<meta>
29*b1cdbd2cSJim Jagielski<topic id="textscalcguideuserdefined_functionxml" indexer="include" status="PUBLISH">
30*b1cdbd2cSJim Jagielski<title id="tit" xml-lang="en-US">User-Defined Functions</title>
31*b1cdbd2cSJim Jagielski<filename>/text/scalc/guide/userdefined_function.xhp</filename>
32*b1cdbd2cSJim Jagielski</topic>
33*b1cdbd2cSJim Jagielski<history>
34*b1cdbd2cSJim Jagielski<created date="2003-10-31T00:00:00">Sun Microsystems, Inc.</created>
35*b1cdbd2cSJim Jagielski<lastedited date="2006-02-07T11:28:53">FPE: Deleted Screenshot and cleaned up
36*b1cdbd2cSJim Jagielskiyj - checked</lastedited>
37*b1cdbd2cSJim Jagielski</history>
38*b1cdbd2cSJim Jagielski</meta>
39*b1cdbd2cSJim Jagielski<body>
40*b1cdbd2cSJim Jagielski<bookmark xml-lang="en-US" branch="index" id="bm_id3155411"><bookmark_value>functions; user-defined</bookmark_value>
41*b1cdbd2cSJim Jagielski<bookmark_value>user-defined functions</bookmark_value>
42*b1cdbd2cSJim Jagielski<bookmark_value>Basic IDE for user-defined functions</bookmark_value>
43*b1cdbd2cSJim Jagielski<bookmark_value>IDE; Basic IDE</bookmark_value>
44*b1cdbd2cSJim Jagielski<bookmark_value>programming;functions</bookmark_value>
45*b1cdbd2cSJim Jagielski</bookmark>
46*b1cdbd2cSJim Jagielski<paragraph role="heading" id="hd_id3155411" xml-lang="en-US" level="1" l10n="U" oldref="1"><variable id="userdefined_function"><link href="text/scalc/guide/userdefined_function.xhp" name="Defining Functions Yourself">User-Defined Functions</link>
47*b1cdbd2cSJim Jagielski</variable></paragraph>
48*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3153969" xml-lang="en-US" l10n="U" oldref="2">You can apply user-defined functions in $[officename] Calc in the following ways:</paragraph>
49*b1cdbd2cSJim Jagielski<list type="unordered">
50*b1cdbd2cSJim Jagielski<listitem>
51*b1cdbd2cSJim Jagielski<paragraph role="listitem" id="par_id3145366" xml-lang="en-US" l10n="CHG" oldref="4">You can define your own functions using the Basic-IDE. This method requires a basic knowledge of programming.</paragraph>
52*b1cdbd2cSJim Jagielski</listitem>
53*b1cdbd2cSJim Jagielski<listitem>
54*b1cdbd2cSJim Jagielski<paragraph role="listitem" id="par_id3153768" xml-lang="en-US" l10n="CHG" oldref="3">You can program functions as <link href="text/scalc/01/04060111.xhp" name="add-ins">add-ins</link>. This method requires an advanced knowledge of programming.</paragraph>
55*b1cdbd2cSJim Jagielski</listitem>
56*b1cdbd2cSJim Jagielski</list>
57*b1cdbd2cSJim Jagielski<paragraph role="heading" id="hd_id3149260" xml-lang="en-US" level="2" l10n="CHG" oldref="6">Defining A Function Using %PRODUCTNAME Basic</paragraph>
58*b1cdbd2cSJim Jagielski<list type="ordered">
59*b1cdbd2cSJim Jagielski<listitem>
60*b1cdbd2cSJim Jagielski<paragraph role="listitem" id="par_id3148456" xml-lang="en-US" l10n="CHG" oldref="7">Choose <item type="menuitem">Tools - Macros - Organize Macros - %PRODUCTNAME Basic</item>.</paragraph>
61*b1cdbd2cSJim Jagielski</listitem>
62*b1cdbd2cSJim Jagielski<listitem>
63*b1cdbd2cSJim Jagielski<paragraph role="listitem" id="par_id3154510" xml-lang="en-US" l10n="U" oldref="8">Click the <emph>Edit</emph> button. You will now see the Basic IDE.</paragraph>
64*b1cdbd2cSJim Jagielski</listitem>
65*b1cdbd2cSJim Jagielski<listitem>
66*b1cdbd2cSJim Jagielski<paragraph role="listitem" id="par_id3150327" xml-lang="en-US" l10n="CHG" oldref="9">Enter the function code. In this example, we define a <item type="literal">VOL(a; b; c)</item> function that calculates the volume of a rectangular solid with side lengths <item type="literal">a</item>, <item type="literal">b</item> and <item type="literal">c</item>:</paragraph>
67*b1cdbd2cSJim Jagielski<paragraph role="code" id="par_id9797426" xml-lang="en-US" l10n="NEW" localize="false">Function VOL(a, b, c)<br/>VOL = a*b*c<br/>End Function</paragraph>
68*b1cdbd2cSJim Jagielski</listitem>
69*b1cdbd2cSJim Jagielski<listitem>
70*b1cdbd2cSJim Jagielski<paragraph role="listitem" id="par_id3155443" xml-lang="en-US" l10n="U" oldref="10">Close the Basic-IDE window.</paragraph>
71*b1cdbd2cSJim Jagielski<paragraph role="listitem" id="par_id3150043" xml-lang="en-US" l10n="CHG" oldref="11">Your function is automatically saved in the default module and is now available. If you apply the function in a Calc document that is to be used on another computer, you can copy the function to the Calc document as described in the next section.</paragraph>
72*b1cdbd2cSJim Jagielski</listitem>
73*b1cdbd2cSJim Jagielski</list>
74*b1cdbd2cSJim Jagielski<paragraph role="heading" id="hd_id3147340" xml-lang="en-US" level="2" l10n="U" oldref="18">Copying a Function To a Document</paragraph>
75*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3145232" xml-lang="en-US" l10n="CHG" oldref="19">In stage 2 of "Defining A Function Using %PRODUCTNAME Basic", in the <emph>Macro</emph> dialog you clicked on <emph>Edit </emph>. As the default, in the <emph>Macro from</emph> field the <emph>My Macros - Standard - Module1</emph> module is selected. The <emph>Standard</emph> library resides locally in your user directory.</paragraph>
76*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3154022" xml-lang="en-US" l10n="U" oldref="20">If you want to copy the user-defined function to a Calc document:</paragraph>
77*b1cdbd2cSJim Jagielski<list type="ordered">
78*b1cdbd2cSJim Jagielski<listitem>
79*b1cdbd2cSJim Jagielski<paragraph role="listitem" id="par_id3150304" xml-lang="en-US" l10n="CHG" oldref="21">Choose <item type="menuitem">Tools - Macros - Organize Macros - %PRODUCTNAME Basic</item> .</paragraph>
80*b1cdbd2cSJim Jagielski</listitem>
81*b1cdbd2cSJim Jagielski<listitem>
82*b1cdbd2cSJim Jagielski<paragraph role="listitem" id="par_id3150086" xml-lang="en-US" l10n="CHG" oldref="22">In the <emph>Macro from</emph> field select <emph>My Macros - Standard - Module1</emph> and click <emph>Edit</emph>.</paragraph>
83*b1cdbd2cSJim Jagielski</listitem>
84*b1cdbd2cSJim Jagielski<listitem>
85*b1cdbd2cSJim Jagielski<paragraph role="listitem" id="par_id3166430" xml-lang="en-US" l10n="CHG" oldref="23">In the Basic-IDE, select the source of your user-defined function and copy it to the clipboard.</paragraph>
86*b1cdbd2cSJim Jagielski</listitem>
87*b1cdbd2cSJim Jagielski<listitem>
88*b1cdbd2cSJim Jagielski<paragraph role="listitem" id="par_idN1081D" xml-lang="en-US" l10n="NEW">Close the Basic-IDE.</paragraph>
89*b1cdbd2cSJim Jagielski</listitem>
90*b1cdbd2cSJim Jagielski<listitem>
91*b1cdbd2cSJim Jagielski<paragraph role="listitem" id="par_id3150517" xml-lang="en-US" l10n="CHG" oldref="24">Choose <item type="menuitem">Tools - Macros - Organize Macros - %PRODUCTNAME Basic</item> .</paragraph>
92*b1cdbd2cSJim Jagielski</listitem>
93*b1cdbd2cSJim Jagielski<listitem>
94*b1cdbd2cSJim Jagielski<paragraph role="listitem" id="par_id3145384" xml-lang="en-US" l10n="CHG" oldref="25">In the <emph>Macro from</emph> field select <emph>(Name of the Calc document) - Standard - Module1</emph>. Click <emph>Edit</emph>.</paragraph>
95*b1cdbd2cSJim Jagielski</listitem>
96*b1cdbd2cSJim Jagielski<listitem>
97*b1cdbd2cSJim Jagielski<paragraph role="listitem" id="par_id3148699" xml-lang="en-US" l10n="U" oldref="26">Paste the clipboard contents in the Basic-IDE of the document.</paragraph>
98*b1cdbd2cSJim Jagielski</listitem>
99*b1cdbd2cSJim Jagielski</list>
100*b1cdbd2cSJim Jagielski<paragraph role="heading" id="hd_id3153305" xml-lang="en-US" level="2" l10n="U" oldref="12">Applying a User-defined Function in $[officename] Calc</paragraph>
101*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3148869" xml-lang="en-US" l10n="CHG" oldref="13">Once you have defined the function <item type="literal">VOL(a; b; c)</item> in the Basic-IDE, you can apply it the same way as the built-in functions of $[officename] Calc.</paragraph>
102*b1cdbd2cSJim Jagielski<list type="ordered">
103*b1cdbd2cSJim Jagielski<listitem>
104*b1cdbd2cSJim Jagielski<paragraph role="listitem" id="par_id3148606" xml-lang="en-US" l10n="CHG" oldref="14">Open a Calc document and enter numbers for the function parameters <item type="literal">a</item>, <item type="literal">b</item>, and <item type="literal">c</item> in cells A1, B1, and C1.</paragraph>
105*b1cdbd2cSJim Jagielski</listitem>
106*b1cdbd2cSJim Jagielski<listitem>
107*b1cdbd2cSJim Jagielski<paragraph role="listitem" id="par_id3156019" xml-lang="en-US" l10n="CHG" oldref="15">Set the cursor in another cell and enter the following:</paragraph>
108*b1cdbd2cSJim Jagielski<paragraph role="code" id="par_id3155264" xml-lang="en-US" l10n="U" oldref="16">=VOL(A1;B1;C1)</paragraph>
109*b1cdbd2cSJim Jagielski</listitem>
110*b1cdbd2cSJim Jagielski<listitem>
111*b1cdbd2cSJim Jagielski<paragraph role="listitem" id="par_id3146776" xml-lang="en-US" l10n="CHG" oldref="17">The function is evaluated and you will see the result in the selected cell.</paragraph>
112*b1cdbd2cSJim Jagielski</listitem>
113*b1cdbd2cSJim Jagielski</list>
114*b1cdbd2cSJim Jagielski<section id="relatedtopics">
115*b1cdbd2cSJim Jagielski<embed href="text/scalc/guide/calculate.xhp#calculate"/>
116*b1cdbd2cSJim Jagielski<embed href="text/scalc/guide/formula_enter.xhp#formula_enter"/>
117*b1cdbd2cSJim Jagielski</section>
118*b1cdbd2cSJim Jagielski</body>
119*b1cdbd2cSJim Jagielski</helpdocument>
120