<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openoffice.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jan+bcf</id>
	<title>Apache OpenOffice Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openoffice.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jan+bcf"/>
	<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/wiki/Special:Contributions/Jan_bcf"/>
	<updated>2026-11-25T13:38:05Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.14</generator>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Documentation/BASIC_Guide/Scope_of_Variables&amp;diff=139209</id>
		<title>Documentation/BASIC Guide/Scope of Variables</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Documentation/BASIC_Guide/Scope_of_Variables&amp;diff=139209"/>
		<updated>2009-09-06T10:32:30Z</updated>

		<summary type="html">&lt;p&gt;Jan bcf: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Documentation/BASICGuideTOC/v2&lt;br /&gt;
|ShowPrevNext=block&lt;br /&gt;
|ShowPrevPage=block&lt;br /&gt;
|PrevPage=Documentation/BASIC Guide/Arrays&lt;br /&gt;
|NextPage=Documentation/BASIC Guide/Constants&lt;br /&gt;
|lang=block&lt;br /&gt;
}}&lt;br /&gt;
{{DISPLAYTITLE:Scope and Life Span of Variables}}&lt;br /&gt;
__NOTOC__ &lt;br /&gt;
A variable in {{OOo}} Basic has a limited life span and a limited scope from which it can be read and used in other program fragments. The amount of time that a variable is retained, as well as where it can be accessed from, depends on its specified location and type.&lt;br /&gt;
&lt;br /&gt;
== Local Variables ==&lt;br /&gt;
&lt;br /&gt;
Variables that are declared in a function or a procedure are called local variables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Sub Test&lt;br /&gt;
  Dim MyInteger As Integer&lt;br /&gt;
  &amp;#039; ...&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Local variables only remain valid as long as the function or the procedure is executing, and then are reset to zero. Each time the function is called, the values generated previously are not available.&lt;br /&gt;
&lt;br /&gt;
To keep the previous values, you must define the variable as &amp;lt;tt&amp;gt;Static&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Sub Test&lt;br /&gt;
  Static MyInteger As Integer&lt;br /&gt;
  &amp;#039; ...&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Documentation/Note|Unlike VBA, {{OOo}} Basic ensures that the name of a local variable is not used simultaneously as a global and a private variable in the module header. When you port a VBA application to {{OOo}} Basic, you must change any duplicate variable names.}}&lt;br /&gt;
&lt;br /&gt;
== Public Domain Variables ==&lt;br /&gt;
&lt;br /&gt;
Public domain variables are defined in the header section of a module by the keyword &amp;lt;tt&amp;gt;Dim&amp;lt;/tt&amp;gt;. These variables are available to all of the modules in their library:&lt;br /&gt;
&lt;br /&gt;
Module A:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim A As Integer&lt;br /&gt;
Sub Test&lt;br /&gt;
  Flip&lt;br /&gt;
  Flop&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
Sub Flip&lt;br /&gt;
 A = A + 1&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Module B:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Sub Flop&lt;br /&gt;
  A = A - 1&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The value of variable &amp;lt;tt&amp;gt;A&amp;lt;/tt&amp;gt; is not changed by the &amp;lt;tt&amp;gt;Test&amp;lt;/tt&amp;gt; function, but is increased by one in the &amp;lt;tt&amp;gt;Flip&amp;lt;/tt&amp;gt; function and decreased by one in the &amp;lt;tt&amp;gt;Flop&amp;lt;/tt&amp;gt; function. Both of these changes to the variable are global.&lt;br /&gt;
&lt;br /&gt;
You can also use the keyword &amp;lt;tt&amp;gt;Public&amp;lt;/tt&amp;gt; instead of &amp;lt;tt&amp;gt;Dim&amp;lt;/tt&amp;gt; to declare a public domain variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Public A As Integer&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A public domain variable is only available so long as the associated macro is executing and then the variable is reset.&lt;br /&gt;
&lt;br /&gt;
== Global Variables ==&lt;br /&gt;
&lt;br /&gt;
In terms of their function, global variables are similar to public domain variables, except that their values are retained even after the associated macro has executed. Global variables are declared in the header section of a module using the keyword &amp;lt;tt&amp;gt;Global&amp;lt;/tt&amp;gt;: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Global A As Integer&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Private Variables ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;Private&amp;lt;/tt&amp;gt; variables are only available in the module in which they are defined. Use the keyword &amp;lt;tt&amp;gt;Private&amp;lt;/tt&amp;gt; to define the variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Private MyInteger As Integer&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If several modules contain a &amp;lt;tt&amp;gt;Private&amp;lt;/tt&amp;gt; variable with the same name, {{OOo}} Basic creates a different variable for each occurrence of the name. In the following example, both module &amp;lt;tt&amp;gt;A&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; have a &amp;lt;tt&amp;gt;Private&amp;lt;/tt&amp;gt; variable called &amp;lt;tt&amp;gt;C&amp;lt;/tt&amp;gt;. The &amp;lt;tt&amp;gt;Test&amp;lt;/tt&amp;gt; function first sets the &amp;lt;tt&amp;gt;Private&amp;lt;/tt&amp;gt; variable in module &amp;lt;tt&amp;gt;A&amp;lt;/tt&amp;gt; and then the &amp;lt;tt&amp;gt;Private&amp;lt;/tt&amp;gt; variable in module &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Module A:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Private C As Integer&lt;br /&gt;
&lt;br /&gt;
Sub Test&lt;br /&gt;
  SetModuleA      &amp;#039; Sets the variable C from module A&lt;br /&gt;
  SetModuleB      &amp;#039; Sets the variable C from module B&lt;br /&gt;
  ShowVarA        &amp;#039; Shows the variable C from module A (= 10)&lt;br /&gt;
  ShowVarB        &amp;#039; Shows the variable C from module B (= 20)&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
Sub SetModuleA&lt;br /&gt;
  C = 10&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
Sub ShowVarA&lt;br /&gt;
  MsgBox C        &amp;#039; Shows the variable C from module A. &lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Module B:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt; &lt;br /&gt;
Private C As Integer&lt;br /&gt;
 &lt;br /&gt;
Sub SetModuleB&lt;br /&gt;
  C = 20&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
Sub ShowVarB&lt;br /&gt;
  MsgBox C        &amp;#039; Shows the variable C from module B.&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Keep in mind that ShowVarB only shows the expected value of C (20) because Sub Test is keeping it in scope. If the calls to SetModuleB and ShowVarB are independent, e.g. SetModuleB is triggered from one toolbar button and ShowVarB is triggered from another toolbar button, then ShowVarB will display a C value of 0 since module variables are reset after each macro completion.&lt;br /&gt;
 &lt;br /&gt;
{{InterWiki Languages BasicGuide|articletitle=Documentation/BASIC Guide/Scope of Variables}}&lt;br /&gt;
{{PDL1}}&lt;/div&gt;</summary>
		<author><name>Jan bcf</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=File:DoobieDoo-example.zip&amp;diff=134333</id>
		<title>File:DoobieDoo-example.zip</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=File:DoobieDoo-example.zip&amp;diff=134333"/>
		<updated>2009-07-07T23:46:59Z</updated>

		<summary type="html">&lt;p&gt;Jan bcf: uploaded a new version of &amp;quot;Image:DoobieDoo-example.zip&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The DoobieDoo Python add-in example.&lt;/div&gt;</summary>
		<author><name>Jan bcf</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Calc/Add-In/Python_How-To&amp;diff=134332</id>
		<title>Calc/Add-In/Python How-To</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Calc/Add-In/Python_How-To&amp;diff=134332"/>
		<updated>2009-07-07T23:43:47Z</updated>

		<summary type="html">&lt;p&gt;Jan bcf: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This example will show you how to create a Python add-in for OpenOffice.org Calc 3.x. The add-in from the fictive DoobieCompany will&lt;br /&gt;
&lt;br /&gt;
* Add custom spreadsheet functions to Calc.&lt;br /&gt;
* Make the custom functions available in Calc&amp;#039;s Function Wizard.&lt;br /&gt;
* Be packaged as an .OXT file so an end-user can install the Add-in by simply double-clicking the .OXT package.&lt;br /&gt;
&lt;br /&gt;
More detailed documentation is available in the full download here [[media:DoobieDoo-example.zip]]. It also includes some&lt;br /&gt;
discussion about how to make user defined functions that work in both Calc and Excel.&lt;br /&gt;
&lt;br /&gt;
The add-in was developed on Windows and the included make-script is Windows only. However, there is nothing particularly platform-specific code in the add-in so I guess you should be able to make it work on a *nix platform too.&lt;br /&gt;
&lt;br /&gt;
You may also visit [http://www.biochemfusion.com/doc/Calc_addin_howto.html the original URL] to see if there is a more up-to-date version available.&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:API]]&lt;br /&gt;
[[Category:Extensions]]&lt;br /&gt;
[[Category:Calc|Add-In/{{SUBPAGENAME}}]]&lt;br /&gt;
[[Category:Add-In]]&lt;br /&gt;
[[Category:Tutorial]]&lt;br /&gt;
[[Category:Python]]&lt;br /&gt;
[[Category:Samples]]&lt;/div&gt;</summary>
		<author><name>Jan bcf</name></author>
	</entry>
</feed>