This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
||||||||||||||||||||||||||||
|
4D v20.6
Creating Arrays
|
Command | Creates or resizes an array of |
ARRAY INTEGER | 2-byte Integer values |
ARRAY LONGINT | 4-byte Integer values |
ARRAY REAL | Real values |
ARRAY TEXT | Text values (up to 2 GB of text per element) (*) |
_o_ARRAY STRING | Text values (obsolete) (*) |
ARRAY DATE | Date values |
ARRAY BOOLEAN | Boolean values |
ARRAY PICTURE | Pictures values |
ARRAY POINTER | Pointer values |
ARRAY OBJECT | Language objects |
ARRAY BLOB | BLOBs |
ARRAY TIME | Times |
Each array declaration command can create or resize one-dimensional or two-dimensional arrays. For more information about two-dimensional arrays, see the Two-dimensional Arrays section.
(*) There is no difference between Text and String arrays. The strLen parameter of the _o_ARRAY STRING command is ignored. It is recommended to use Text arrays. The _o_ARRAY STRING command is only kept for compatibility reasons.
The following line of code creates (declares) an Integer array of 10 elements:
ARRAY INTEGER(aiAnArray;10)
Then, the following code resizes that same array to 20 elements:
ARRAY INTEGER(aiAnArray;20)
Then, the following code resizes that same array to no elements:
ARRAY INTEGER(aiAnArray;0)
You reference the elements in an array by using curly braces ({…}). A number is used within the braces to address a particular element; this number is called the element number. The following lines put five names into the array called atNames and then display them in alert windows:
ARRAY TEXT(atNames;5)
atNames{1}:="Richard"
atNames{2}:="Sarah"
atNames{3}:="Sam"
atNames{4}:="Jane"
atNames{5}:="John"
For($vlElem;1;5)
ALERT("The element #"+String($vlElem)+" is equal to: "+atNames{$vlElem})
End for
Note the syntax atNames{$vlElem}. Rather than specifying a numeric literal such as atNames{3}, you can use a numeric variable to indicate which element of an array you are addressing.
Using the iteration provided by a loop structure (ARRAY TO LIST, LIST TO ARRAY or PLAY), compact pieces of code can address all or part of the elements in an array.
There are other 4D commands that can create and work with arrays. More particularly:
_o_ARRAY STRING
ARRAY BLOB
ARRAY BOOLEAN
ARRAY DATE
ARRAY INTEGER
ARRAY LONGINT
ARRAY OBJECT
ARRAY PICTURE
ARRAY POINTER
ARRAY REAL
ARRAY TEXT
ARRAY TIME
Arrays
Two-dimensional Arrays
Product: 4D
Theme: Arrays
4D Language Reference ( 4D v20)
4D Language Reference ( 4D v20.1)
4D Language Reference ( 4D v20.2)
4D Language Reference ( 4D v20.3)
4D Language Reference ( 4D v20.4)
4D Language Reference ( 4D v20.5)
4D Language Reference ( 4D v20.6)