blob: 13abdb3052fb64863ee3cec6613a3113200ca939 (
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
71
|
<?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="textsbasicshared03103500xml" indexer="include" status="PUBLISH">
<title id="tit" xml-lang="en-US">Static Statement</title>
<filename>/text/sbasic/shared/03103500.xhp</filename>
</topic>
</meta>
<body>
<section id="static">
<bookmark xml-lang="en-US" branch="index" id="bm_id3149798">
<bookmark_value>Static statement</bookmark_value>
</bookmark>
<h1 id="hd_id3149798"><link href="text/sbasic/shared/03103500.xhp">Static Statement</link></h1>
<paragraph id="par_id3153311" role="paragraph" xml-lang="en-US">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 id="par_id3147264" role="warning" xml-lang="en-US">The <emph>Static statement</emph> cannot be used to define variable arrays. Arrays must be specified according to a fixed size.</paragraph>
<h2 id="hd_id3149657">Syntax:</h2>
<bascode>
<paragraph id="par_id3150400" role="bascode" xml-lang="en-US">Static VarName[(start To end)] [As VarType], VarName2[(start To end)] [As VarType], ...</paragraph>
</bascode>
<h2 id="hd_id3148452">Example:</h2>
<bascode>
<paragraph id="par_idm1340791536" role="bascode" localize="false" xml-lang="en-US">Sub ExampleStatic</paragraph>
<paragraph id="par_idm1340790304" role="bascode" localize="false" xml-lang="en-US">Dim iCount As Integer, iResult As Integer</paragraph>
<paragraph id="par_idm1340789040" role="bascode" localize="false" xml-lang="en-US"> For iCount = 0 To 2</paragraph>
<paragraph id="par_idm1340787808" role="bascode" localize="false" xml-lang="en-US"> iResult = InitVar()</paragraph>
<paragraph id="par_idm1340786560" role="bascode" localize="false" xml-lang="en-US"> Next iCount</paragraph>
<paragraph id="par_id3150870" role="bascode" xml-lang="en-US"> MsgBox iResult,0,"The answer is"</paragraph>
<paragraph id="par_idm1340783600" role="bascode" localize="false" xml-lang="en-US">End Sub</paragraph>
<paragraph id="par_idm1340782368" role="bascode" localize="false" xml-lang="en-US"> </paragraph>
<paragraph id="par_id3151115" role="bascode" xml-lang="en-US">' Function for initialization of the static variable</paragraph>
<paragraph id="par_idm1340779328" role="bascode" localize="false" xml-lang="en-US">Function InitVar() As Integer</paragraph>
<paragraph id="par_idm1340778080" role="bascode" localize="false" xml-lang="en-US"> Static iInit As Integer</paragraph>
<paragraph id="par_id1057161" role="bascode" xml-lang="en-US"> Const iMinimum As Integer = 40 ' minimum return value of this function</paragraph>
<paragraph id="par_id580462" role="bascode" xml-lang="en-US"> If iInit = 0 Then ' check if initialized</paragraph>
<paragraph id="par_idm1340950464" role="bascode" localize="false" xml-lang="en-US"> iInit = iMinimum</paragraph>
<paragraph id="par_idm1340949216" role="bascode" localize="false" xml-lang="en-US"> Else</paragraph>
<paragraph id="par_idm1340947984" role="bascode" localize="false" xml-lang="en-US"> iInit = iInit + 1</paragraph>
<paragraph id="par_idm1340946736" role="bascode" localize="false" xml-lang="en-US"> End If</paragraph>
<paragraph id="par_idm1340945504" role="bascode" localize="false" xml-lang="en-US"> InitVar = iInit</paragraph>
<paragraph id="par_idm1340944272" role="bascode" localize="false" xml-lang="en-US">End Function</paragraph>
</bascode>
</body>
</helpdocument>
|