ReDim Statement

Declares or redefines variables or arrays.


ReDim Statement diagram

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.


variable: Any variable or array name.

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

primitive data types fragment

Byte: Byte variable (0-255)

Boolean: Boolean variable (True, False)

Currency: Currency variable (Currency with 4 Decimal places)

Date αŸ– αž’αžαŸαžšβ€‹αž€αžΆαž›β€‹αž”αžšαž·αž…αŸ’αž†αŸαž‘

Double: Double-precision floating-point variable (1,79769313486232 x 10E308 - 4,94065645841247 x 10E-324)

Integer αŸ– αž’αžαŸαžšβ€‹αž…αŸ†αž“αž½αž“β€‹αž‚αžαŸ‹ (-32768 - 32767)

Long αŸ– αž’αžαŸαžšβ€‹αž…αŸ†αž“αž½αž“β€‹αž‚αžαŸ‹β€‹αž’αŸ† (-2.147.483.648 - 2.147.483.647)

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

Single αŸ– αž’αžαŸαžšβ€‹αž–αž·αžβ€‹αžŠαŸ‚αž›β€‹αž˜αžΆαž“β€‹αž…αŸ†αž“αž½αž“β€‹αž‘αžŸαž—αžΆαž‚β€‹αžαŸ‚β€‹αž˜αž½αž™ (3,402823 x 10E38 - 1,401298 x 10E-45).

String αŸ– αž’αžαŸαžšβ€‹αžαŸ’αžŸαŸ‚β€‹αž’αž€αŸ’αžŸαžšβ€‹αžŠαŸ‚αž›β€‹αž˜αžΆαž“β€‹αžαž½β€‹αž’αž€αŸ’αžŸαžš ASCII αž’αžαž·β€‹αž”αžšαž˜αžΆ 64,000Β αŸ”

Variant: Variant variable type (contains all types, specified by definition). If a type name is not specified, variables are automatically defined as Variant Type, unless a statement from DefBool to DefVar is used.

object: Universal Network object (UNO) object or ClassModule object instance.

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

Type declaration characters fragment

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













array: Array declaration.

array fragment

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

start and end can be numerical expressions if ReDim is applied at the procedure level.

LibreOffice Basic αž‚αžΆαŸ†αž‘αŸ’αžšβ€‹αž’αžΆαžšαŸβ€‹αž˜αž½αž™ αž¬β€‹αž…αŸ’αžšαžΎαž“β€‹αžœαž·αž˜αžΆαžαŸ’αžšβ€‹αžŠαŸ‚αž›β€‹αžαŸ’αžšαžΌαžœβ€‹αž”αžΆαž“β€‹αž€αŸ†αžŽαžαŸ‹β€‹αžŠαŸ„αž™β€‹αž”αŸ’αžšαž—αŸαž‘β€‹αž’αžαŸαžšβ€‹αžŠαŸ‚αž›β€‹αž”αžΆαž“β€‹αž”αž‰αŸ’αž‡αžΆαž€αŸ‹β€‹Β αŸ” αž’αžΆαžšαŸβ€‹αž‚αžΊβ€‹αžŸαž˜αžŸαŸ’αžšαž” αž”αžΎβ€‹αž€αž˜αŸ’αž˜αžœαž·αž’αžΈβ€‹αž˜αžΆαž“β€‹αž”αž‰αŸ’αž‡αžΈ αž¬β€‹αžαžΆαžšαžΆαž„β€‹αžŠαŸ‚αž›β€‹αž’αŸ’αž“αž€β€‹αž…αž„αŸ‹β€‹αž€αŸ‚αžŸαž˜αŸ’αžšαž½αž›Β αŸ” αž‚αž»αžŽβ€‹αžŸαž˜αŸ’αž”αžαŸ’αžαž·β€‹αž“αŸƒβ€‹αž’αžΆαžšαŸβ€‹αž‚αžΊβ€‹αžœαžΆβ€‹αž’αžΆαž…β€‹αž€αŸ†αžŽαžαŸ‹β€‹αž’αžΆαžŸαž™αžŠαŸ’αž‹αžΆαž“β€‹αž’αžΆαžαž»β€‹αž“αžΈαž˜αž½αž™β€‹αŸ— αž’αžΆαžŸαŸ’αžšαŸαž™β€‹αž‘αŸ…β€‹αžαžΆαž˜β€‹αžŸαž“αŸ’αž‘αžŸαŸ’αžŸαž“αŸ αžŠαŸ‚αž›β€‹αž’αžΆαž…β€‹αžαŸ’αžšαžΌαžœβ€‹αž”αžΆαž“β€‹αž‚αžŽαž“αžΆβ€‹αž‡αžΆβ€‹αž€αž“αŸ’αžŸαŸ„αž˜ αž¬β€‹αž’αžαŸαžšβ€‹αž›αŸαžΒ αŸ”

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.

αž§αž‘αžΆαž αžšαžŽαŸ αŸ–

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

Please support us!