21.08.2013 Views

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Arrays 19<br />

Multi- Dimensional Data Fields<br />

In addition to single dimensional data fields, <strong>OpenOffice</strong>.<strong>org</strong> Basic also supports work with<br />

multi-dimensional data fields. The corresponding dimensions are separated from one<br />

another by commas. The example<br />

Dim MyIntArray(5, 5) As Integer<br />

defines an integer array with two dimensions, each with 6 indexes (can be addressed<br />

through the indexes 0 to 5). The entire array can record a total of 6 x 6 = 36 integer values.<br />

You can define hundreds of dimensions in <strong>OpenOffice</strong>.<strong>org</strong> Basic Arrays; however, the<br />

amount of available memory limits the number of dimensions you can have.<br />

Dynamic Changes in the Dimensions of Data Fields<br />

The previous examples are based on data fields of a specified dimension. You can also<br />

define arrays in which the dimension of the data fields dynamically changes. For example,<br />

you can define an array to contain all of the words in a text that begin with the letter A. As<br />

the number of these words is initially unknown, you need to be able to subsequently change<br />

the field limits. To do this in <strong>OpenOffice</strong>.<strong>org</strong> Basic, use the following call:<br />

ReDim MyArray(10)<br />

Unlike VBA, where you can only dimension dynamic arrays by using Dim MyArray(), <strong>OpenOffice</strong>.<strong>org</strong><br />

Basic lets you change both static and dynamic arrays using ReDim.<br />

The following example changes the dimension of the initial array so that it can record 11 or<br />

21 values:<br />

Dim MyArray(4) As Integer ' Declaration with five elements<br />

' ...<br />

ReDim MyArray(10) As Integer ' Increase to 11 elements<br />

' ...<br />

ReDim MyArray(20) As Integer ' Increase to 21 elements<br />

When you reset the dimensions of an array, you can use any of the options outlined in the<br />

previous sections. This includes declaring multi-dimensional data fields and specifying<br />

explicit start and end values. When the dimensions of the data field are changed, all<br />

contents are lost. If you want to keep the original values, use the Preserve command:<br />

Dim MyArray(10) As Integer ' Defining the initial<br />

' dimensions<br />

' ...

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!