ReDim Statement

Declara unha variábel ou unha matriz.


[ReDim]Dim VarName [(start To end)] [As VarType][, VarName2 [(start To end)] [As VarType][,...]]

Optionally, you can add the Preserve keyword as a parameter to preserve the contents of the array that is redimensioned.


VarName: Any variable or array name.

Start, End: Numerical values or constants that define the number of elements (NumberElements=(end-start)+1) and the index range.

Inicio e Fin poden ser expresións numéricas se se usa ReDim no nivel do procedemento.

VarType: Keyword that declares the data type of a variable.

Keyword: Variable type

Bool: Boolean variable (True, False)

Date: Date variable

Double: Double floating point variable (1.79769313486232x10E308 - 4.94065645841247x10E-324)

Integer: Integer variable (-32768 - 32767)

Long: Long integer variable (-2,147,483,648 - 2,147,483,647)

Object: Object variable (can only be subsequently defined by Set!)

[Single]: Single floating-point variable (3.402823x10E38 - 1.401298x10E-45). If no key word is specified, a variable is defined as Single, unless a statement from DefBool to DefVar is used.

String: String variable containing a maximum of 64,000 ASCII characters.

Variant: Variant variable type (can contain all types and is set by definition).

In LibreOffice Basic, you do not need to declare variables explicitly. However, you need to declare an array before you can use them. You can declare a variable with the Dim statement, using commas to separate multiple declarations. To declare a variable type, enter a type-declaration character following the name or use a corresponding key word.

LibreOffice Basic supports single or multi-dimensional arrays that are defined by a specified variable type. Arrays are suitable if the program contains lists or tables that you want to edit. The advantage of arrays is that it is possible to address individual elements according to indexes, which can be formulated as numeric expressions or variables.

Existen dúas formas de estabelecer o intervalo de índices para matrices declaradas coa instrución Dim:

DIM texto(20) As String REM 21 elementos numerados de 0 a 20

DIM texto(5 to 25) As String REM 21 elementos numerados de 5 a 25

DIM texto$(-15 to 5) As String REM 21 elementos (incluído 0),

rem numerados de -15 a 5

Os campos de variábeis, independentemente do tipo, poden converterse en dinámicos por medio de ReDIM no nivel de procedemento en métodos ou funcións. Normalmente, o tamaño dunha matriz só pode definirse unha vez e non é modificábel. Dentro dun procedemento, pode declarar unha matriz usando a instrución ReDim con expresións numéricas para definir o intervalo dos tamaños de campo.


Sub ExampleRedim
Dim iVar() As Integer, iCount As Integer
ReDim iVar(5) As Integer
For iCount = 1 To 5
    iVar(iCount) = iCount
Next iCount
ReDim iVar(10) As Integer
For iCount = 1 To 10
    iVar(iCount) = iCount
Next iCount
End Sub

Please support us!