diff options
Diffstat (limited to 'helpcontent2/source/text/sbasic/shared/03090406.xhp')
-rw-r--r-- | helpcontent2/source/text/sbasic/shared/03090406.xhp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/helpcontent2/source/text/sbasic/shared/03090406.xhp b/helpcontent2/source/text/sbasic/shared/03090406.xhp new file mode 100644 index 000000000..eb10a54c3 --- /dev/null +++ b/helpcontent2/source/text/sbasic/shared/03090406.xhp @@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="UTF-8"?> +<helpdocument version="1.0"> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . +--> + +<meta> + <topic id="textsbasicshared03090406xml" indexer="include" status="PUBLISH"> + <title id="tit" xml-lang="en-US">Function Statement</title> + <filename>/text/sbasic/shared/03090406.xhp</filename> + </topic> +</meta> + +<body> + +<section id="function"> +<bookmark xml-lang="en-US" branch="index" id="bm_id3153346"> + <bookmark_value>Function statement</bookmark_value> +</bookmark> + +<paragraph id="hd_id3153346" role="heading" level="1" xml-lang="en-US"><link href="text/sbasic/shared/03090406.xhp" name="Function Statement">Function Statement</link></paragraph> +<paragraph id="par_id3159158" role="paragraph" xml-lang="en-US">Defines a subroutine that can be used as an expression to determine a return type.</paragraph> +</section> + +<section id="TwinMethods"> +<note id="par_id661588586825434"><literal>Sub</literal> or <literal>Function</literal> statements are similar methods, without distinction. They receive parameters by reference allowing them to be modified. %PRODUCTNAME Basic compiler accepts their respective syntax to be used interchangeably.</note> +</section> + +<embed href="text/sbasic/shared/00000003.xhp#functsyntax"/> +<paragraph role="paragraph" id="par_id971588473588701"> + <image src="media/helpimg/sbasic/Function_statement.svg" id="img_id4156296484514"><alt xml-lang="en-US" id="alt_id15152796484514">Function Statement diagram</alt></image></paragraph> +<bascode> + <paragraph role="bascode" id="bas_id151588427099190" localize="false">[Private | Public] Function Name[char] (argument1 [As Type][, argument2[char][,...]]) [As typename]</paragraph> + <paragraph role="bascode" id="bas_id541588427401158" xml-lang="en-US"> statements</paragraph> + <paragraph role="bascode" id="bas_id981588427406211" localize="false"> [Exit Function]</paragraph> + <paragraph role="bascode" id="bas_id631588427410583" xml-lang="en-US"> statements</paragraph> + <paragraph role="bascode" id="bas_id581588427417085" localize="false">End Function</paragraph> +</bascode> + +<embed href="text/sbasic/shared/00000003.xhp#functparameters"/> +<section id="RoutineScope"> + <paragraph role="paragraph" id="par_id81588429476557"> <emph>scope:</emph> Function default scope is <literal>Public</literal>. A <literal>Private</literal> scope denotes a module internal routine, not intended to be used from other modules.</paragraph> +</section> + +<paragraph id="par_id3153193" role="paragraph" xml-lang="en-US"> <emph>name:</emph> Name of the subroutine to contain the value returned by the function.</paragraph> +<paragraph id="par_id3147229" role="paragraph" xml-lang="en-US"> <emph>arguments:</emph> Parameters to be passed to the subroutine.</paragraph> + +<embed href="text/sbasic/shared/fragments.xhp#argument"/> +<embed href="text/sbasic/shared/fragments.xhp#typename"/> +<embed href="text/sbasic/shared/fragments.xhp#char"/> + +<section id="BasicExamples"> +<h2 id="hd_id3163710" xml-lang="en-US">Examples:</h2> +<bascode> +<paragraph id="par_idm1340981728" role="bascode" localize="false" xml-lang="en-US">Sub ExampleExit</paragraph> +<paragraph id="par_idm1340980496" role="bascode" localize="false" xml-lang="en-US">Dim sReturn As String</paragraph> +<paragraph id="par_idm1340979264" role="bascode" localize="false" xml-lang="en-US">Dim sListArray(10) As String</paragraph> +<paragraph id="par_idm1340978016" role="bascode" localize="false" xml-lang="en-US">Dim siStep As Single</paragraph> +<paragraph id="par_id3152939" role="bascode" xml-lang="en-US"> For siStep = 0 To 10 ' Fill array with test data</paragraph> +<paragraph id="par_idm1340975040" role="bascode" localize="false" xml-lang="en-US"> sListArray(siStep) = chr$(siStep + 65)</paragraph> +<paragraph id="par_idm1340973776" role="bascode" localize="false" xml-lang="en-US"> MsgBox sListArray(siStep)</paragraph> +<paragraph id="par_idm1340972528" role="bascode" localize="false" xml-lang="en-US"> Next siStep</paragraph> +<paragraph id="par_idm1340971296" role="bascode" localize="false" xml-lang="en-US"> sReturn = LinSearch(sListArray(), "B")</paragraph> +<paragraph id="par_idm1340970032" role="bascode" localize="false" xml-lang="en-US"> Print sReturn</paragraph> +<paragraph id="par_idm1340968800" role="bascode" localize="false" xml-lang="en-US">End Sub</paragraph> +<paragraph id="par_idm1340967568" role="bascode" localize="false" xml-lang="en-US"> </paragraph> +<paragraph id="par_idm1340966320" role="bascode" localize="false" xml-lang="en-US">Function LinSearch( sList(), sItem As String ) As Integer</paragraph> +<paragraph id="par_idm1340965040" role="bascode" localize="false" xml-lang="en-US">Dim iCount As Integer</paragraph> +<paragraph id="par_id3154943" role="bascode" xml-lang="en-US">' Linsearch searches a TextArray:sList() for a TextEntry:</paragraph> +<paragraph id="par_id3155601" role="bascode" xml-lang="en-US">' Return value Is the index of the entry Or 0 (Null)</paragraph> +<paragraph id="par_idm1340960304" role="bascode" localize="false" xml-lang="en-US"> For iCount=1 To Ubound( sList() )</paragraph> +<paragraph id="par_idm1340959056" role="bascode" localize="false" xml-lang="en-US"> If sList( iCount ) = sItem Then</paragraph> +<paragraph id="par_id3153707" role="bascode" xml-lang="en-US"> Exit For ' sItem found</paragraph> +<paragraph id="par_idm1340956080" role="bascode" localize="false" xml-lang="en-US"> End If</paragraph> +<paragraph id="par_idm1340954848" role="bascode" localize="false" xml-lang="en-US"> Next iCount</paragraph> +<paragraph id="par_idm1340953616" role="bascode" localize="false" xml-lang="en-US"> If iCount = Ubound( sList() ) Then iCount = 0</paragraph> +<paragraph id="par_idm1340952352" role="bascode" localize="false" xml-lang="en-US"> LinSearch = iCount</paragraph> +<paragraph id="par_idm1340951120" role="bascode" localize="false" xml-lang="en-US">End Function</paragraph> +</bascode> +</section> + +</body> + +</helpdocument>
\ No newline at end of file |