<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.harlamenkov.ru/index.php?action=history&amp;feed=atom&amp;title=EN%2Fdocumentation%2Fbasic_guide%2Fworking_with_variables</id>
	<title>EN/documentation/basic guide/working with variables - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.harlamenkov.ru/index.php?action=history&amp;feed=atom&amp;title=EN%2Fdocumentation%2Fbasic_guide%2Fworking_with_variables"/>
	<link rel="alternate" type="text/html" href="https://wiki.harlamenkov.ru/index.php?title=EN/documentation/basic_guide/working_with_variables&amp;action=history"/>
	<updated>2026-11-11T14:00:45Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://wiki.harlamenkov.ru/index.php?title=EN/documentation/basic_guide/working_with_variables&amp;diff=15878&amp;oldid=prev</id>
		<title>Sancho: Created page with &quot;&lt;section begin=title /&gt;&lt;noinclude&gt;{{DISPLAYTITLE:&lt;/noinclude&gt;Working with Variables&lt;noinclude&gt;}}&lt;/noinclude&gt;&lt;section end=title /&gt;{{BreadCrumbL10n}}  {{Documentation/BASICGuideTOC...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.harlamenkov.ru/index.php?title=EN/documentation/basic_guide/working_with_variables&amp;diff=15878&amp;oldid=prev"/>
		<updated>2011-09-01T13:24:07Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;section begin=title /&amp;gt;&amp;lt;noinclude&amp;gt;{{DISPLAYTITLE:&amp;lt;/noinclude&amp;gt;Working with Variables&amp;lt;noinclude&amp;gt;}}&amp;lt;/noinclude&amp;gt;&amp;lt;section end=title /&amp;gt;{{BreadCrumbL10n}}  {{Documentation/BASICGuideTOC...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;section begin=title /&amp;gt;&amp;lt;noinclude&amp;gt;{{DISPLAYTITLE:&amp;lt;/noinclude&amp;gt;Working with Variables&amp;lt;noinclude&amp;gt;}}&amp;lt;/noinclude&amp;gt;&amp;lt;section end=title /&amp;gt;{{BreadCrumbL10n}}&lt;br /&gt;
&lt;br /&gt;
{{Documentation/BASICGuideTOC&lt;br /&gt;
|ShowPrevNext=block&lt;br /&gt;
|ShowPrevPage=block&lt;br /&gt;
|PrevPage=EN/documentation/basic_guide/program_overview&lt;br /&gt;
|NextPage=EN/documentation/basic_guide/strings&lt;br /&gt;
|lang=block&lt;br /&gt;
}}&lt;br /&gt;
 &lt;br /&gt;
==Implicit Variable Declaration ==&lt;br /&gt;
&lt;br /&gt;
Basic languages are designed to be easy to use. As a result, {{OOo}} Basic enables the creation of a variable through simple usage and without an explicit declaration. In other words, a variable exists from the moment that you include it in your code. Depending on the variables that are already present, the following example declares up to three new variables:&lt;br /&gt;
&lt;br /&gt;
 a = b + c&lt;br /&gt;
&lt;br /&gt;
Declaring variables implicitly is not good programming practice because it can result in the inadvertent introduction of a new variable through, for example, a typing error. Instead of producing an error message, the interpreter initializes the typing error as a new variable with a value of 0. It can be very difficult to locate errors of this kind in your code.&lt;br /&gt;
&lt;br /&gt;
==Explicit Variable Declaration ==&lt;br /&gt;
&lt;br /&gt;
To prevent errors caused by an implicit declaration of variables, {{OOo}} Basic provides a switch called:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Option Explicit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This must be listed in the first program line of each module and ensures that an error message is issued if one of the variables used is not declared. The &amp;lt;tt&amp;gt;Option Explicit&amp;lt;/tt&amp;gt; switch should be included in all Basic modules.&lt;br /&gt;
&lt;br /&gt;
In its simplest form, the command for an explicit declaration of a variable is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim MyVar&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example declares a variable with the name &amp;lt;tt&amp;gt;MyVar&amp;lt;/tt&amp;gt; and the type &amp;lt;tt&amp;gt;variant&amp;lt;/tt&amp;gt;. A variant is a universal variable that can record all conceivable values, including strings, whole numbers, floating point figures, and Boolean values. Here are a few examples of Variant variables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
MyVar = &amp;quot;Hello World&amp;quot;      ' Assignment of a string&lt;br /&gt;
MyVar = 1                  ' Assignment of a whole number&lt;br /&gt;
MyVar = 1.0                ' Assignment of a floating point number&lt;br /&gt;
MyVar = True               ' Assignment of a Boolean value&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The variables declared in the previous example can even be used for different variable types in the same program. Although this provides considerable flexibility, it is best to restrict a variable to one variable type. When {{OOo}} Basic encounters an incorrectly defined variable type in a particular context, an error message is generated.&lt;br /&gt;
&lt;br /&gt;
Use the following style when you make a type-bound variable declaration:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim MyVar As Integer   ' Declaration of a variable of the integer type&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The variable is declared as an integer type and can record whole number values. You can also use the following style to declare an integer type variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim MyVar%          ' Declaration of a variable of the integer type&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Dim instruction can record several variable declarations:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim MyVar1, MyVar2&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to assign the variables to a permanent type, you must make separate assignments for each variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim MyVar1 As Integer, MyVar2 As Integer&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you do not declare the type for a variable, {{OOo}} Basic assigns the variable a variant type. For example, in the following variable declaration, &amp;lt;tt&amp;gt;MyVar1&amp;lt;/tt&amp;gt; becomes a variant and &amp;lt;tt&amp;gt;MyVar2&amp;lt;/tt&amp;gt; becomes an integer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim MyVar1, MyVar2 As Integer&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following sections list the variable types that are available in {{OOo}} Basic and describe how they can be used and declared.&lt;br /&gt;
 &lt;br /&gt;
{{PDL1}}&lt;/div&gt;</summary>
		<author><name>Sancho</name></author>
		
	</entry>
</feed>