Contingut

# Expressió ReDim

Declara o redefineix variables o matrius.

### Sintaxi:

    ReDim [Preserve] variable [(start To end)] [As type-name][, variable2 [(start To end)] [As type-name][,...]]

Optionally, add the Preserve keyword to preserve the contents of the array that is redimensioned. ReDim can only be used in subroutines.

### Paràmetres:

variable: Any variable or array name.

typename Paraula clau que declara el tipus de dades d'una variable.

Byte: Byte variable (0-255)

Boolean: Boolean variable (True, False)

Currency: Currency variable (Currency with 4 Decimal places)

Data: Variable de data

Doble Variable de coma flotant de precisió doble (1797693134862332 x 10E308 - 494065645841247 x 10E-324)

Integer: Variable d'enter (-32768 - 32767)

Long: Variable d'enter gran (-2.147.483.648 - 2.147.483.647)

Object: Object variable (Note: this variable can only subsequently be defined with Set!)

Single: Variable de coma flotant de precisió senzilla (3,402823 x 10E38 - 1,401298 x 10E-45).

String: String variable consisting of a maximum of 2,147,483,647 characters.

Variant Variant Variant Tipus (conté tots els tipus especificats per definició). Si no s'especifica un nom de tipus les variables es defineixen automàticament com a Tipus Variant llevat que s'utilitzi una declaració de DefBool a DefVar.

objecte Universal Network objecte (UNO) objecte o ClassModule instància d'objecte.

char: Special character that declares the data type of a variable.

In LibreOffice Basic, you do not need to declare variables explicitly. However, you need to declare arrays 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 type keyword name.

Declaration character | Variable type name
--- | ---
% | Integer
& | Long
! | Single
# | Double
$ | String
@ | Currency

array: Array declaration.

inici final Valors numèrics o constants que defineixen el nombre d'elements (NumberElements=(final-start)+1) i l'interval d'índexs.

inicia i final poden ser expressions numèriques si ReDim s'aplica al nivell de procediment.

El LibreOffice Basic admet matrius de dimensió senzilla o múltiple que es defineixen amb un tipus de variable especificat. Les matrius són adequades si el programa conté llistes o taules que voleu editar. L'avantatge de les matrius és que és possible adreçar elements individuals segons els índexs, que es poden formular com a expressions numèriques o variables.

Arrays are declared with the Dim statement. There are multiple ways to define the index range:

      Dim text(20) As String ' 21 elements numbered from 0 to 20
      Dim value(5 to 25) As Integer ' 21 values numbered from 5 to 25
      Dim amount(-15 to 5) As Currency ' 21 amounts (including 0), numbered from -15 to 5
      REM Two-dimensional data field
      Dim table$(20,2) ' 63 items; from 0 to 20 level 1, from 0 to 20 level 2 and from 0 to 20 level 3.

You can declare an array types as dynamic if a ReDim statement defines the number of dimensions in the subroutine or the function that contains the array. Generally, you can only define an array dimension once, and you cannot modify it. Within a subroutine, you can declare an array with ReDim. You can only define dimensions with numeric expressions. This ensures that the fields are only as large as necessary.

## Exemple:

    Sub ExampleRedim
        Dim iVar() As Integer, iCount As Byte
        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

Ens cal la vostra ajuda!