ReDim Statement

Deklaruje premenn√ļ alebo pole.

Syntax:

[ReDim]Dim N√°zovPremennej [(zańćiatok To koniec)] [As TypPremennej][, N√°zovPremenne2 [(zańćiatok To koniec)] [As TypPremennej][,...]]

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

Paremetre:

N√°zovPremennej: Platn√Ĺ n√°zov premennej alebo pońĺa.

Zańćiatok, Koniec: ńĆ√≠seln√© hodnoty alebo konŇ°tanty, ktor√© definuj√ļ pońćet prvkov (PońćetPrvkov = (koniec-zańćiatok) +1) a rozsah indexu.

Zańćiatok a Koniec m√īŇĺu byŇ• ńć√≠seln√© v√Ĺrazy, ak sa ReDim pouŇĺije na √ļrovni proced√ļry.

TypPremennej: Kńĺ√ļńćov√© slovo urńćuj√ļce d√°tov√Ĺ typ premennej.

Kńĺ√ļńćov√© slovo: Typ premennej

Bool: Boolovsk√° premenn√° (True, False)

Date: D√°tumov√° premenn√°

Double: Premenn√° v pl√°vaj√ļcej r√°dovej ńćiarke (1,79769313486232 √ó 10E308 - 4,94065645841247 √ó 10E-324)

Integer: Celońć√≠seln√° premenn√° (-32768 - 32767)

Long: Dlh√° celońć√≠seln√° premenn√° (-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: ReŇ•azec obsahuj√ļci maxim√°lne 64000 ASCII znakov.

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

V jazyku LibreOffice Basic nemus√≠te premenn√© deklarovaŇ• explicitne. AvŇ°ak mus√≠te pred pouŇĺit√≠m deklarovaŇ• pole. Premenn√ļ je moŇĺn√© deklarovaŇ• pomocou pr√≠kazu Dim a pouŇĺiŇ• ńćiarky na oddelenie niekońĺk√Ĺch deklar√°ci√≠. Ak chcete deklarovaŇ• typ premennej, pouŇĺite znak typovej deklar√°cie alebo zodpovedaj√ļce kńĺ√ļńćov√© slovo.

LibreOffice Basic podporuje jedno- i viacrozmern√© polia, ktor√© sa definuj√ļ urńćen√Ĺm typom premennej. Polia s√ļ vhodn√©, ak chcete v programe pouŇĺiŇ• zoznam alebo tabuńĺku, ktor√© chcete upravovaŇ•. V√Ĺhodou pol√≠ je, Ňĺe k jednotliv√Ĺm prvkom je moŇĺn√© pristupovaŇ• pomocou indexov, ktor√© moŇĺno vyjadriŇ• ńć√≠seln√Ĺm v√Ĺrazom alebo premennou.

There are two ways to set the range of indices for arrays declared with the Dim statement:

DIM text(20) as String REM 21 prvkov ńć√≠slovan√Ĺch od 0 do 20

DIM text(5 to 25) as String REM 21 prvkov ńć√≠slovan√Ĺch od 5 do 25

DIM text(-15 to 5) as String REM 21 prvkov (vr√°tane 0)

REM ńć√≠slovan√© od -15 do 5

Variable fields, regardless of type, can be made dynamic if they are dimensioned by ReDim at the procedure level in subroutines or functions. Normally, you can only set the range of an array once and you cannot modify it. Within a procedure, you can declare an array using the ReDim statement with numeric expressions to define the range of the field sizes.

Príklad:

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