1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?> 2cdf0e10cSrcweir 3cdf0e10cSrcweir 4*ce44d6c1SAndrew Rist<!--*********************************************************** 5cdf0e10cSrcweir * 6*ce44d6c1SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 7*ce44d6c1SAndrew Rist * or more contributor license agreements. See the NOTICE file 8*ce44d6c1SAndrew Rist * distributed with this work for additional information 9*ce44d6c1SAndrew Rist * regarding copyright ownership. The ASF licenses this file 10*ce44d6c1SAndrew Rist * to you under the Apache License, Version 2.0 (the 11*ce44d6c1SAndrew Rist * "License"); you may not use this file except in compliance 12*ce44d6c1SAndrew Rist * with the License. You may obtain a copy of the License at 13*ce44d6c1SAndrew Rist * 14*ce44d6c1SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 15*ce44d6c1SAndrew Rist * 16*ce44d6c1SAndrew Rist * Unless required by applicable law or agreed to in writing, 17*ce44d6c1SAndrew Rist * software distributed under the License is distributed on an 18*ce44d6c1SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19*ce44d6c1SAndrew Rist * KIND, either express or implied. See the License for the 20*ce44d6c1SAndrew Rist * specific language governing permissions and limitations 21*ce44d6c1SAndrew Rist * under the License. 22*ce44d6c1SAndrew Rist * 23*ce44d6c1SAndrew Rist ***********************************************************--> 24*ce44d6c1SAndrew Rist 25*ce44d6c1SAndrew Rist 26cdf0e10cSrcweir 27cdf0e10cSrcweir<helpdocument version="1.0"> 28cdf0e10cSrcweir<meta> 29cdf0e10cSrcweir<topic id="textscalcguideuserdefined_functionxml" indexer="include" status="PUBLISH"> 30cdf0e10cSrcweir<title id="tit" xml-lang="en-US">User-Defined Functions</title> 31cdf0e10cSrcweir<filename>/text/scalc/guide/userdefined_function.xhp</filename> 32cdf0e10cSrcweir</topic> 33cdf0e10cSrcweir<history> 34cdf0e10cSrcweir<created date="2003-10-31T00:00:00">Sun Microsystems, Inc.</created> 35cdf0e10cSrcweir<lastedited date="2006-02-07T11:28:53">FPE: Deleted Screenshot and cleaned up 36cdf0e10cSrcweiryj - checked</lastedited> 37cdf0e10cSrcweir</history> 38cdf0e10cSrcweir</meta> 39cdf0e10cSrcweir<body> 40cdf0e10cSrcweir<bookmark xml-lang="en-US" branch="index" id="bm_id3155411"><bookmark_value>functions; user-defined</bookmark_value> 41cdf0e10cSrcweir<bookmark_value>user-defined functions</bookmark_value> 42cdf0e10cSrcweir<bookmark_value>Basic IDE for user-defined functions</bookmark_value> 43cdf0e10cSrcweir<bookmark_value>IDE; Basic IDE</bookmark_value> 44cdf0e10cSrcweir<bookmark_value>programming;functions</bookmark_value> 45cdf0e10cSrcweir</bookmark> 46cdf0e10cSrcweir<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> 47cdf0e10cSrcweir</variable></paragraph> 48cdf0e10cSrcweir<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> 49cdf0e10cSrcweir<list type="unordered"> 50cdf0e10cSrcweir<listitem> 51cdf0e10cSrcweir<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> 52cdf0e10cSrcweir</listitem> 53cdf0e10cSrcweir<listitem> 54cdf0e10cSrcweir<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> 55cdf0e10cSrcweir</listitem> 56cdf0e10cSrcweir</list> 57cdf0e10cSrcweir<paragraph role="heading" id="hd_id3149260" xml-lang="en-US" level="2" l10n="CHG" oldref="6">Defining A Function Using %PRODUCTNAME Basic</paragraph> 58cdf0e10cSrcweir<list type="ordered"> 59cdf0e10cSrcweir<listitem> 60cdf0e10cSrcweir<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> 61cdf0e10cSrcweir</listitem> 62cdf0e10cSrcweir<listitem> 63cdf0e10cSrcweir<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> 64cdf0e10cSrcweir</listitem> 65cdf0e10cSrcweir<listitem> 66cdf0e10cSrcweir<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> 67cdf0e10cSrcweir<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> 68cdf0e10cSrcweir</listitem> 69cdf0e10cSrcweir<listitem> 70cdf0e10cSrcweir<paragraph role="listitem" id="par_id3155443" xml-lang="en-US" l10n="U" oldref="10">Close the Basic-IDE window.</paragraph> 71cdf0e10cSrcweir<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> 72cdf0e10cSrcweir</listitem> 73cdf0e10cSrcweir</list> 74cdf0e10cSrcweir<paragraph role="heading" id="hd_id3147340" xml-lang="en-US" level="2" l10n="U" oldref="18">Copying a Function To a Document</paragraph> 75cdf0e10cSrcweir<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> 76cdf0e10cSrcweir<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> 77cdf0e10cSrcweir<list type="ordered"> 78cdf0e10cSrcweir<listitem> 79cdf0e10cSrcweir<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> 80cdf0e10cSrcweir</listitem> 81cdf0e10cSrcweir<listitem> 82cdf0e10cSrcweir<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> 83cdf0e10cSrcweir</listitem> 84cdf0e10cSrcweir<listitem> 85cdf0e10cSrcweir<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> 86cdf0e10cSrcweir</listitem> 87cdf0e10cSrcweir<listitem> 88cdf0e10cSrcweir<paragraph role="listitem" id="par_idN1081D" xml-lang="en-US" l10n="NEW">Close the Basic-IDE.</paragraph> 89cdf0e10cSrcweir</listitem> 90cdf0e10cSrcweir<listitem> 91cdf0e10cSrcweir<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> 92cdf0e10cSrcweir</listitem> 93cdf0e10cSrcweir<listitem> 94cdf0e10cSrcweir<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> 95cdf0e10cSrcweir</listitem> 96cdf0e10cSrcweir<listitem> 97cdf0e10cSrcweir<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> 98cdf0e10cSrcweir</listitem> 99cdf0e10cSrcweir</list> 100cdf0e10cSrcweir<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> 101cdf0e10cSrcweir<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> 102cdf0e10cSrcweir<list type="ordered"> 103cdf0e10cSrcweir<listitem> 104cdf0e10cSrcweir<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> 105cdf0e10cSrcweir</listitem> 106cdf0e10cSrcweir<listitem> 107cdf0e10cSrcweir<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> 108cdf0e10cSrcweir<paragraph role="code" id="par_id3155264" xml-lang="en-US" l10n="U" oldref="16">=VOL(A1;B1;C1)</paragraph> 109cdf0e10cSrcweir</listitem> 110cdf0e10cSrcweir<listitem> 111cdf0e10cSrcweir<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> 112cdf0e10cSrcweir</listitem> 113cdf0e10cSrcweir</list> 114cdf0e10cSrcweir<section id="relatedtopics"> 115cdf0e10cSrcweir<embed href="text/scalc/guide/calculate.xhp#calculate"/> 116cdf0e10cSrcweir<embed href="text/scalc/guide/formula_enter.xhp#formula_enter"/> 117cdf0e10cSrcweir</section> 118cdf0e10cSrcweir</body> 119cdf0e10cSrcweir</helpdocument> 120