dim / redim

Prev Next

Function Names

dim, redim

Description

dim defines one or more arrays with specified dimensions and initial values. If the variable is already existing as an array or a structure, then all member variables will be eliminated and initialized accordingly.

redim will preserve the the existing array contents as long the size is increased. In this case, only the added members will be initialized. The arrays can also be downsized where the excessive members will be eliminated.

Impact on base variables: The base variable remains unaffected. These functions affect the members only.

Note: B4P supports spontaneous array creation and extension by simply write-accessing a member which does not yet exist. However, only this designated member will be assigned where the additional members to be initialized contain void values. Example: a[10] = 1; Here, a[0]..a[9] are initialized with void values.

Call as: procedure

Restrictions

Indirect parameter passing is disabled

Parameter count

3, 6, 9, etc.

Parameters

No.TypeDescription
1, 4, 7, ...
code
variable
:string
Variable name

The array will be built on the specified variable. Member variables of existing arrays and structures are allowed so you can build more complex data structures.

2, 5, 8, ...
input
numeral
set of numerals
Dimension

Following types are supported:

numeral A one-dimensional array will be created.
parameters set of numerals A multi-dimensional array will be created, depending on number of elements specified. No array will be defined if an empty set is provided.

Default value: text
3, 6, 9, ...
input
valid types Initial value

The initial value will be applied for every variable member.

Examples

       a[] = 123; // Will be preserved

       dim( a[], 5, Hi, b[], {}, 1, a[2], {2,2}, 0 );
       redim( a[], 8, Ho );

       see( a[] ); // Nested arrays
       see( b[] ); // Void

       dim( c[], { 2, 2 }, 1 );        // 2x2 array
       redim( c[], { 3, 3}, 3 );       // Extend to 3x3 array

       see( c[] );

Output

a[]                     123  "123"                 (numeral,full access)
Array [   0]            Hi                         (softquoted string,full access)
Array [   1]            Hi                         (softquoted string,full access)
Array [   2]            Hi                         (softquoted string,full access)
  Array [   0]          0  "0"                     (numeral,full access)
    Array [   0]        0  "0"                     (numeral,full access)
    Array [   1]        0  "0"                     (numeral,full access)
  Array [   1]          0  "0"                     (numeral,full access)
    Array [   0]        0  "0"                     (numeral,full access)
    Array [   1]        0  "0"                     (numeral,full access)
Array [   3]            Hi                         (softquoted string,full access)
Array [   4]            Hi                         (softquoted string,full access)
Array [   5]            Ho                         (softquoted string,full access)
Array [   6]            Ho                         (softquoted string,full access)
Array [   7]            Ho                         (softquoted string,full access)

b[]                     [Void]                     (void,full access)

c[]                     [Void]                     (void,full access)
Array [   0]            1  "1"                     (numeral,full access)
  Array [   0]          1  "1"                     (numeral,full access)
  Array [   1]          1  "1"                     (numeral,full access)
  Array [   2]          3  "3"                     (numeral,full access)
Array [   1]            1  "1"                     (numeral,full access)
  Array [   0]          1  "1"                     (numeral,full access)
  Array [   1]          1  "1"                     (numeral,full access)
  Array [   2]          3  "3"                     (numeral,full access)
Array [   2]            3  "3"                     (numeral,full access)
  Array [   0]          3  "3"                     (numeral,full access)
  Array [   1]          3  "3"                     (numeral,full access)
  Array [   2]          3  "3"                     (numeral,full access)

Try it yourself: Open LIB_Function_dim.b4p in B4P_Examples.zip. Decompress before use.

See also

dim protect
redim protect
array
insert memebers