summaryrefslogtreecommitdiff
path: root/source/text/sbasic/shared/03103500.xhp
blob: 9c4968cebe953f59f2cb3b8433c07b8ba0841264 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?xml version="1.0" encoding="UTF-8"?>


<!--
 * 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 .
 -->


	
<helpdocument version="1.0">
<meta>
<topic id="textsbasicshared03103500xml" indexer="include" status="PUBLISH">
<title id="tit" xml-lang="en-US">Static Statement [Runtime]</title>
<filename>/text/sbasic/shared/03103500.xhp</filename>
</topic>
<history>
<created date="2003-10-31T00:00:00">Sun Microsystems, Inc.</created>
<lastedited date="2005-11-11T13:14:35">converted from old format - fpe</lastedited>
</history>
</meta>
<body>
<section id="static">
<bookmark xml-lang="en-US" branch="index" id="bm_id3149798"><bookmark_value>Static statement</bookmark_value>
</bookmark>
<paragraph role="heading" id="hd_id3149798" xml-lang="en-US" level="1" l10n="U" oldref="1"><link href="text/sbasic/shared/03103500.xhp" name="Static Statement [Runtime]">Static Statement [Runtime]</link></paragraph>
<paragraph role="paragraph" id="par_id3153311" xml-lang="en-US" l10n="U" oldref="2">Declares a variable or an array at the procedure level within a subroutine or a function, so that the values of the variable or the array are retained after exiting the subroutine or function. Dim statement conventions are also valid.</paragraph>
</section>
<paragraph role="warning" id="par_id3147264" xml-lang="en-US" l10n="U" oldref="3">The <emph>Static statement</emph> cannot be used to define variable arrays. Arrays must be specified according to a fixed size.</paragraph>
<paragraph role="heading" id="hd_id3149657" xml-lang="en-US" level="2" l10n="U" oldref="4">Syntax:</paragraph>
<bascode>
<paragraph role="bascode" id="par_id3150400" xml-lang="en-US" oldref="5">Static VarName[(start To end)] [As VarType], VarName2[(start To end)] [As VarType], ...</paragraph>
</bascode>
<paragraph role="heading" id="hd_id3148452" xml-lang="en-US" level="2" l10n="U" oldref="6">Example:</paragraph>
<bascode>
<paragraph role="bascode" localize="false" xml-lang="en-US">Sub ExampleStatic</paragraph>
<paragraph role="bascode" localize="false" xml-lang="en-US">Dim iCount As Integer, iResult As Integer</paragraph>
<paragraph role="bascode" localize="false" xml-lang="en-US">    For iCount = 0 To 2</paragraph>
<paragraph role="bascode" localize="false" xml-lang="en-US">        iResult = InitVar()</paragraph>
<paragraph role="bascode" localize="false" xml-lang="en-US">    Next iCount</paragraph>
<paragraph role="bascode" id="par_id3150870" xml-lang="en-US" l10n="CHG" oldref="11">    MsgBox iResult,0,"The answer is"</paragraph>
<paragraph role="bascode" localize="false" xml-lang="en-US">End Sub</paragraph>
<paragraph role="bascode" localize="false" xml-lang="en-US"> </paragraph>
<paragraph role="bascode" id="par_id3151115" xml-lang="en-US" l10n="U" oldref="15">' Function for initialization of the static variable</paragraph>
<paragraph role="bascode" localize="false" xml-lang="en-US">Function InitVar() As Integer</paragraph>
<paragraph role="bascode" localize="false" xml-lang="en-US">    Static iInit As Integer</paragraph>
<paragraph role="bascode" id="par_id1057161" xml-lang="en-US">    Const iMinimum As Integer = 40 ' minimum return value of this function</paragraph>
<paragraph role="bascode" id="par_id580462" xml-lang="en-US">    If iInit = 0 Then ' check if initialized</paragraph>
<paragraph role="bascode" localize="false" xml-lang="en-US">        iInit = iMinimum</paragraph>
<paragraph role="bascode" localize="false" xml-lang="en-US">    Else</paragraph>
<paragraph role="bascode" localize="false" xml-lang="en-US">        iInit = iInit + 1</paragraph>
<paragraph role="bascode" localize="false" xml-lang="en-US">    End If</paragraph>
<paragraph role="bascode" localize="false" xml-lang="en-US">    InitVar = iInit</paragraph>
<paragraph role="bascode" localize="false" xml-lang="en-US">End Function</paragraph>
</bascode>
</body>
</helpdocument>