<?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%2Farrays</id>
	<title>EN/documentation/basic guide/arrays - 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%2Farrays"/>
	<link rel="alternate" type="text/html" href="https://wiki.harlamenkov.ru/index.php?title=EN/documentation/basic_guide/arrays&amp;action=history"/>
	<updated>2026-11-11T14:01:07Z</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/arrays&amp;diff=15883&amp;oldid=prev</id>
		<title>Sancho: Created page with &quot;&lt;section begin=title /&gt;&lt;noinclude&gt;{{DISPLAYTITLE:&lt;/noinclude&gt;Arrays&lt;noinclude&gt;}}&lt;/noinclude&gt;&lt;section end=title /&gt;{{BreadCrumbL10n}}   {{Documentation/BASICGuideTOC |ShowPrevNext=...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.harlamenkov.ru/index.php?title=EN/documentation/basic_guide/arrays&amp;diff=15883&amp;oldid=prev"/>
		<updated>2011-09-01T14:10:21Z</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;Arrays&amp;lt;noinclude&amp;gt;}}&amp;lt;/noinclude&amp;gt;&amp;lt;section end=title /&amp;gt;{{BreadCrumbL10n}}   {{Documentation/BASICGuideTOC |ShowPrevNext=...&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;Arrays&amp;lt;noinclude&amp;gt;}}&amp;lt;/noinclude&amp;gt;&amp;lt;section end=title /&amp;gt;{{BreadCrumbL10n}}&lt;br /&gt;
&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/date&lt;br /&gt;
|NextPage=EN/documentation/basic_guide/scope_of_variables&lt;br /&gt;
|lang=block&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__ &lt;br /&gt;
In addition to simple variables (scalars), {{OOo}} Basic also supports arrays (data fields). A data field contains several variables, which are addressed through an index.&lt;br /&gt;
&lt;br /&gt;
= Defining Arrays =&lt;br /&gt;
Arrays can be defined as follows:&lt;br /&gt;
&lt;br /&gt;
==Simple Arrays==&lt;br /&gt;
&lt;br /&gt;
An array declaration is similar to that of a simple variable declaration. However, unlike the variable declaration, the array name is followed by parentheses which contain the specifications for the number of elements. The expression&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim MyArray(3)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declares an array that has four variables of the variant data type, namely &amp;lt;tt&amp;gt;MyArray(0)&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;MyArray(1)&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;MyArray(2)&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;MyArray(3)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You can also declare type-specific variables in an array. For example, the following line declares an array with four integer variables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim MyInteger(3) As Integer&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the previous examples, the index for the array always begins with the standard start value of zero. As an alternative, a validity range with start and end values can be specified for the data field declaration. The following example declares a data field that has six integer values and which can be addressed using the indexes 5 to 10:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim MyInteger(5 To 10) As Integer&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The indexes do not need to be positive values. The following example also shows a correct declaration, but with negative data field limits:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim MyInteger(-10 To -5) As Integer&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It declares an integer data field with 6 values that can be addressed using the indexes -10 to -5.&lt;br /&gt;
&lt;br /&gt;
There are no practical limits on the indexes or on the number of elements in an array, so long as there is enough memory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim s(-53000 to 89000) As String&lt;br /&gt;
s(-52000) = &amp;quot;aa&amp;quot;&lt;br /&gt;
s(79999) = &amp;quot;bb&amp;quot;&lt;br /&gt;
print s(-52000), s(79999)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{VBAnote|Other limit values sometimes apply for data field indexes in VBA. The same also applies to the maximum number of elements possible per dimension. The values valid there can be found in the relevant VBA documentation.}}&lt;br /&gt;
&lt;br /&gt;
==Specified Value for Start Index==&lt;br /&gt;
&lt;br /&gt;
The start index of a data field usually begins with the value 0. Alternatively, you can change the start index for all data field declarations to the value 1 by using the call:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Option Base 1&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The call must be included in the header of a module if you want it to apply to all array declarations in the module. However, this call does not affect the UNO sequences that are defined through the {{OOo}} API whose index always begins with 0. To improve clarity, you should avoid using Option Base 1.&lt;br /&gt;
&lt;br /&gt;
The number of elements in an array is not affected if you use &amp;lt;tt&amp;gt;Option Base 1&amp;lt;/tt&amp;gt;, only the start index changes. The declaration&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Option Base 1&lt;br /&gt;
' ...&lt;br /&gt;
Dim MyInteger(3)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
creates 4 integer variables which can be described with the expressions &amp;lt;tt&amp;gt;MyInteger(1)&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;MyInteger(2)&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;MyInteger(3)&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;MyInteger(4)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{VBAnote|In {{OOo}} Basic, the expression &amp;lt;tt&amp;gt;Option Base 1&amp;lt;/tt&amp;gt; does not affect the number of elements in an array as it does in VBA. It is, rather, the start index which moves in {{OOo}} Basic. While the declaration &amp;lt;tt&amp;gt;MyInteger(3)&amp;lt;/tt&amp;gt; creates three integer values in VBA with the indexes 1 to 3, the same declaration in {{OOo}} Basic creates four integer values with the indexes 1 to 4. By using &amp;lt;tt&amp;gt;Option Compatible&amp;lt;/tt&amp;gt;, {{OOo}} Basic behaves like VBA.}}&lt;br /&gt;
&lt;br /&gt;
==Multi-Dimensional Data Fields==&lt;br /&gt;
&lt;br /&gt;
In addition to single dimensional data fields, {{OOo}} Basic also supports work with multi-dimensional data fields. The corresponding dimensions are separated from one another by commas. The example&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim MyIntArray(5, 5) As Integer&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
defines an integer array with two dimensions, each with 6 indexes (can be addressed through the indexes 0 to 5). The entire array can record a total of 6 x 6 = 36 integer values.&lt;br /&gt;
&lt;br /&gt;
You can define hundreds of dimensions in {{OOo}} Basic Arrays; however, the amount of available memory limits the number of dimensions you can have.&lt;br /&gt;
&lt;br /&gt;
==Dynamic Changes in the Dimensions of Data Fields==&lt;br /&gt;
&lt;br /&gt;
The previous examples are based on data fields of a specified dimension. You can also define arrays in which the dimension of the data fields dynamically changes. For example, you can define an array to contain all of the words in a text that begin with the letter A. As the number of these words is initially unknown, you need to be able to subsequently change the field limits. To do this in {{OOo}} Basic, use the following call:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
ReDim MyArray(10)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{VBAnote|Unlike VBA, where you can only dimension dynamic arrays by using &amp;lt;tt&amp;gt;Dim MyArray()&amp;lt;/tt&amp;gt;, {{OOo}} Basic lets you change both static and dynamic arrays using &amp;lt;tt&amp;gt;ReDim&amp;lt;/tt&amp;gt;.}}&lt;br /&gt;
&lt;br /&gt;
The following example changes the dimension of the initial array so that it can record 11 or 21 values:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim MyArray(4) As Integer ' Declaration with five elements &lt;br /&gt;
' ...&lt;br /&gt;
ReDim MyArray(10) As Integer ' Increase to 11 elements&lt;br /&gt;
' ... &lt;br /&gt;
ReDim MyArray(20) As Integer ' Increase to 21 elements&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you reset the dimensions of an array, you can use any of the options outlined in the previous sections. This includes declaring multi-dimensional data fields and specifying explicit start and end values. When the dimensions of the data field are changed, all contents are lost. If you want to keep the original values, use the &amp;lt;tt&amp;gt;Preserve&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim MyArray(10) As Integer ' Defining the initial &lt;br /&gt;
' dimensions&lt;br /&gt;
' ... &lt;br /&gt;
ReDim Preserve MyArray(20) As Integer ' Increase in &lt;br /&gt;
' data field, while&lt;br /&gt;
' retaining content&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you use &amp;lt;tt&amp;gt;Preserve&amp;lt;/tt&amp;gt;, ensure that the number of dimensions and the type of variables remain the same.&lt;br /&gt;
&lt;br /&gt;
{{VBAnote|Unlike VBA, where only the upper limit of the last dimension of a data field can be changed through &amp;lt;tt&amp;gt;Preserve&amp;lt;/tt&amp;gt;, {{OOo}} Basic lets you change other dimensions as well.}}&lt;br /&gt;
&lt;br /&gt;
If you use &amp;lt;tt&amp;gt;ReDim&amp;lt;/tt&amp;gt; with &amp;lt;tt&amp;gt;Preserve&amp;lt;/tt&amp;gt;, you must use the same data type as specified in the original data field declaration.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining the Dimensions of Data Fields==&lt;br /&gt;
&lt;br /&gt;
Functions LBound() and UBound() return respectively the lowest permitted index value and the highest permitted index value of an array. This is useful when an array has changed its dimensions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim MyArray(10) As Integer&lt;br /&gt;
' ... some instructions&lt;br /&gt;
Dim n As Integer&lt;br /&gt;
n = 47 ' could be the result of a computation&lt;br /&gt;
Redim MyArray(n) As Integer&lt;br /&gt;
MsgBox(LBound(MyArray))  ' displays : 0&lt;br /&gt;
MsgBox(UBound(MyArray))  ' displays : 47&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a multi-dimensional array you need to specify the position (1 to n) of the index you want to know the permitted lower and upper values:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim MyArray(10, 13 to 28) As Integer&lt;br /&gt;
MsgBox(LBound(MyArray, 2))  ' displays : 13&lt;br /&gt;
MsgBox(UBound(MyArray, 2))  ' displays : 28&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Empty arrays==&lt;br /&gt;
&lt;br /&gt;
In some cases, especially when dealing with the API, you need to declare an empty array. Such array is declared without dimension, but may later be filled by an API function or with a Redim statement:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim s() As String ' declare an empty array&lt;br /&gt;
' --- later in the program ...&lt;br /&gt;
Redim s(13) As String&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You cannot assign a value to an empty array, since it does not contain any elements.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;signature&amp;quot; of an empty array is that UBound() returns -1 and LBound() returns 0:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim MyArray() As Integer&lt;br /&gt;
MsgBox(LBound(MyArray))  ' displays : 0&lt;br /&gt;
MsgBox(UBound(MyArray))  ' displays : -1&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some API functions return an array containing elements (indexed from zero) or return an empty array. Use UBound() to check if the returned array is empty.&lt;br /&gt;
&lt;br /&gt;
= Defining values for arrays =&lt;br /&gt;
&lt;br /&gt;
Values for the Array fields can be stored like this:&lt;br /&gt;
&lt;br /&gt;
 MyArray(0) = &amp;quot;somevalue&amp;quot;&lt;br /&gt;
&lt;br /&gt;
= Accessing Arrays =&lt;br /&gt;
&lt;br /&gt;
Accessing values in an array works like this:&lt;br /&gt;
&lt;br /&gt;
 MsgBox(&amp;quot;Value:&amp;quot; &amp;amp; MyArray(0))&lt;br /&gt;
&lt;br /&gt;
= Array Creation, value assignment and access example =&lt;br /&gt;
And example containing all steps that show real array usage:&lt;br /&gt;
&lt;br /&gt;
 Sub TestArrayAxess&lt;br /&gt;
 	Dim MyArray(3)&lt;br /&gt;
 	MyArray(0) = &amp;quot;lala&amp;quot;&lt;br /&gt;
 	MsgBox(&amp;quot;Value:&amp;quot; &amp;amp; MyArray(0))&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{PDL1}}&lt;/div&gt;</summary>
		<author><name>Sancho</name></author>
		
	</entry>
</feed>