Difference between revisions of "DECLARE"

From Lianjapedia
Jump to: navigation, search
 
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
''[[DECLARE Commands|DECLARE ... commands]]''
 +
 
==Purpose==
 
==Purpose==
 
Declare an array
 
Declare an array
 
  
 
==Syntax==
 
==Syntax==
Line 12: Line 13:
  
 
==See Also==
 
==See Also==
[[AAVERAGE()]], [[ACHOICE()]], [[ACOPY()]], [[ADEL()]], [[ADIR()]], [[AFIELDS()]], [[AFILL()]], [[AINS()]], [[ALEN()]], [[AMAX()]], [[AMIN()]], [[APPEND FROM ARRAY]], [[ARRAY()]], [[ASORT()]], [[ASUM()]], [[COPY TO ARRAY]], [[DIMENSION]], [[GATHER]], [[IN_ARRAY()]], [[IS_ARRAY()]], [[LOCAL]], [[NAMESPACE]], [[NAMESPACE()]], [[PRIVATE]], [[PUBLIC]], [[RELEASE]], [[RESTORE]], [[SAVE]], [[SCATTER]], [[VARINFO()]]
+
[[AAVERAGE()]], [[ACOPY()]], [[ADEL()]], [[ADIR()]], [[AFIELDS()]], [[AFILL()]], [[AINS()]], [[ALEN()]], [[AMAX()]], [[AMIN()]], [[APPEND FROM ARRAY]], [[ARRAY()]], [[ASORT()]], [[ASUM()]], [[COPY TO ARRAY]], [[DIMENSION]], [[GATHER]], [[GETMEMBER()]], [[IN_ARRAY()]], [[IS_ARRAY()]], [[LOCAL]], [[NAMESPACE]], [[NAMESPACE()]], [[PRIVATE]], [[PUBLIC]], [[RELEASE]], [[RESTORE]], [[SAVE]], [[SCATTER]], [[VARINFO()]]
 
+
  
 
==Description==
 
==Description==
Line 19: Line 19:
  
 
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.
 
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>)====
 
====[<expN>] | (<expN>)====
Line 33: Line 32:
  
 
<code lang="recital">
 
<code lang="recital">
aDynarray.name = [Recital Corporation]
+
aDynarray.name = [Lianja Inc]
aDynarray.email = [info@recital.com]
+
aDynarray.email = [sales@lianja.com]
 
</code>
 
</code>
  
Line 41: Line 40:
 
<code lang="recital">
 
<code lang="recital">
 
? aDynarray.name
 
? aDynarray.name
Recital Corporation
+
Lianja Inc
 
? aDynarray[2]
 
? aDynarray[2]
info@recital.com
+
sales@lianja.com
 
</code>
 
</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 78: Line 76:
 
// Dynamic array
 
// Dynamic array
 
declare aDynarray[]
 
declare aDynarray[]
aDynarray.name = [Recital Corporation]
+
aDynarray.name = [Lianja Inc]
 
? aDynarray.name
 
? aDynarray.name
Recital Corporation
+
Lianja Inc
 
? aDynarray[1]
 
? aDynarray[1]
Recital Corporation
+
Lianja Inc
 
</code>
 
</code>
  
 
==Products==
 
Recital Server, Recital
 
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:Commands]]
 
[[Category:Commands]]
[[Category:Array Processing]]
+
[[Category:Declaring Variables and Arrays]]
[[Category:Array Processing Commands]]
+

Latest revision as of 09:58, 3 August 2016

DECLARE ... commands

Purpose

Declare an array

Syntax

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

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

DECLARE <array>[] | ()

See Also

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

Description

The DECLARE command is used to declare fixed one or two-dimensional arrays and dynamic arrays.

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.

[] | ()

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

aDynarray.name = [Lianja Inc]
aDynarray.email = [sales@lianja.com]

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

? aDynarray.name
Lianja Inc
? aDynarray[2]
sales@lianja.com

Notes: The brackets shown for this command do not indicate optional expressions but are a necessary part of the syntax. Arrays can also be declared using any of the scoping commands: LOCAL, PRIVATE and PUBLIC.

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 = [Lianja Inc]
? aDynarray.name
Lianja Inc
? aDynarray[1]
Lianja Inc