Difference between revisions of "DECLARE"

From Recital Documentation Wiki
Jump to: navigation, search
Line 9: Line 9:
  
 
DECLARE <array>[<expN1>,<expN2>] | (<expN1>,<expN2>)
 
DECLARE <array>[<expN1>,<expN2>] | (<expN1>,<expN2>)
 +
 +
DECLARE <array>[] | ()
  
  
Line 16: Line 18:
  
 
==Description==
 
==Description==
The DECLARE command is used to declare memory variables and fixed one or two-dimensional arrays.  Memory variables declared using the DECLARE command are initialized to .F. and are private to the declaring procedure.
+
The DECLARE command is used to declare memory variables, fixed one or two-dimensional arrays and dynamic arrays.  Memory variables declared using the DECLARE command are initialized to .F. and are private to the declaring procedure.
 +
 
 +
For fixed arrays, the array size is set at its declaration.  Dynamic arrays are declared without a size.  Array subscripts can be referenced using square brackets or round brackets.
  
The size of an array is fixed at its declaration.  Both one and two dimensional arrays subscripts can be referenced using square brackets or round brackets.
 
  
 
====[<expN>] | (<expN>)====
 
====[<expN>] | (<expN>)====
Line 26: Line 29:
 
For two-dimensional arrays, <expN1> represents the number of rows and <expN2> represents the number of columns in the array.  Elements are subsequently referenced by <array>[<expN1>,<expN2>] or <array>(<expN1>,<expN2>).  The elements of a two dimensional array can also be referenced, as if the array were one dimensional, using <array>[<expN1>] or <array>(<expN>).
 
For two-dimensional arrays, <expN1> represents the number of rows and <expN2> represents the number of columns in the array.  Elements are subsequently referenced by <array>[<expN1>,<expN2>] or <array>(<expN1>,<expN2>).  The elements of a two dimensional array can also be referenced, as if the array were one dimensional, using <array>[<expN1>] or <array>(<expN>).
  
Arrays can be declared as any size.  Values are assigned into arrays using the '=' operator.  Arrays can then be used in a similar way to memory variables.  Complete arrays can be initialized with one assignment.  Array references start at 1,1 for two-dimensional arrays, and 1 for one-dimensional arrays.  They can also be declared as private or public by using the PRIVATE and PUBLIC commands.  Arrays can be saved to memory files with the SAVE TO command and then later restored with the RESTORE FROM command.
+
Fixed arrays can be declared as any size.  Values are assigned into arrays using the '=' operator.  Arrays can then be used in a similar way to memory variables.  Complete arrays can be initialized with one assignment.  Array references start at 1,1 for two-dimensional arrays, and 1 for one-dimensional arrays.  They can also be declared as private or public by using the PRIVATE and PUBLIC commands.  Arrays can be saved to memory files with the SAVE TO command and then later restored with the RESTORE FROM command.
 +
 
 +
====[] | ()====
 +
Dynamic arrays are declared without specifying a size.  Elements are added using arrayname.element syntax.
 +
 
 +
<code lang="recital">
 +
aDynarray.name = [Recital Corporation]
 +
aDynarray.email = [info@recital.com]
 +
</code>
 +
 
 +
They can then be referenced by element number or by element name.
 +
 
 +
<code lang="recital">
 +
? aDynarray.name
 +
Recital Corporation
 +
? aDynarray[2]
 +
info@recital.com
 +
</code>
 +
 
  
 
Notes: The brackets shown for this command do not indicate optional expressions but are a necessary part of the syntax.
 
Notes: The brackets shown for this command do not indicate optional expressions but are a necessary part of the syntax.
Line 56: Line 77:
 
declare aPayroll[reccount(), fcount()]
 
declare aPayroll[reccount(), fcount()]
 
copy to array aPayroll for city = "LONDON"
 
copy to array aPayroll for city = "LONDON"
 +
 +
// Dynamic array
 +
declare aDynarray[]
 +
aDynarray.name = [Recital Corporation]
 +
? aDynarray.name
 +
Recital Corporation
 +
? aDynarray[1]
 +
Recital Corporation
 
</code>
 
</code>
  

Revision as of 15:10, 3 November 2009

Purpose

Declare an array


Syntax

DECLARE <memvar>

DECLARE <array>[<expN>] | (<expN>)

DECLARE <array>[<expN1>,<expN2>] | (<expN1>,<expN2>)

DECLARE <array>[] | ()


See Also

AAVERAGE(), ACHOICE(), ACOPY(), ADEL(), ADIR(), AFIELDS(), AFILL(), AINS(), ALEN(), AMAX(), AMIN(), APPEND FROM ARRAY, ASORT(), ASUM(), COPY TO ARRAY, DIMENSION, GATHER, PRIVATE, PUBLIC, RELEASE, RESTORE, SAVE, SCATTER


Description

The DECLARE command is used to declare memory variables, fixed one or two-dimensional arrays and dynamic arrays. Memory variables declared using the DECLARE command are initialized to .F. and are private to the declaring procedure.

For fixed arrays, the array size is set at its declaration. Dynamic arrays are declared without a size. Array subscripts can be referenced using square brackets or round brackets.


[<expN>] | (<expN>)

For one-dimensional arrays, [<expN>] specifies the total number of elements in the array. Elements are subsequently referenced using the notation <array>[<expN>] or <array>(<expN>).

[<expN1>,<expN2>] | (<expN1>,<expN2>)

For two-dimensional arrays, <expN1> represents the number of rows and <expN2> represents the number of columns in the array. Elements are subsequently referenced by <array>[<expN1>,<expN2>] or <array>(<expN1>,<expN2>). The elements of a two dimensional array can also be referenced, as if the array were one dimensional, using <array>[<expN1>] or <array>(<expN>).

Fixed arrays can be declared as any size. Values are assigned into arrays using the '=' operator. Arrays can then be used in a similar way to memory variables. Complete arrays can be initialized with one assignment. Array references start at 1,1 for two-dimensional arrays, and 1 for one-dimensional arrays. They can also be declared as private or public by using the PRIVATE and PUBLIC commands. Arrays can be saved to memory files with the SAVE TO command and then later restored with the RESTORE FROM command.

[] | ()

Dynamic arrays are declared without specifying a size. Elements are added using arrayname.element syntax.

aDynarray.name = [Recital Corporation]
aDynarray.email = [info@recital.com]

They can then be referenced by element number or by element name.

? aDynarray.name
Recital Corporation
? aDynarray[2]
info@recital.com


Notes: The brackets shown for this command do not indicate optional expressions but are a necessary part of the syntax.


Example

// Declare one-dimensional array of 4000 elements
declare aTable[4000]
// Assign 0 to all elements
aTable = 0
// Insert individual element values into array
aTable[1] = 10
aTable[2] = "Hello"
aTable[3] = "World"
aTable[4] = date()
// Print value of element 2
? aTable[2]
Hello
 
// Another example
declare twodim[3,3]
twodim[2,3] = "hello world"
? twodim[6]
hello world
 
// Another example
use payroll
declare aPayroll[reccount(), fcount()]
copy to array aPayroll for city = "LONDON"
 
// Dynamic array
declare aDynarray[]
aDynarray.name = [Recital Corporation]
? aDynarray.name
Recital Corporation
? aDynarray[1]
Recital Corporation


Products

Recital Database Server, Recital Mirage Server, Recital Terminal Developer