Variable Definition

The variable-definition option is used with DEFINE DATA LOCAL, DEFINE DATA INDEPENDENT, DEFINE DATA CONTEXT and DEFINE DATA OBJECT.

In the variable-definition option, you may specify either a scalar-definition or an array-definition:

../graphics/cbo2.gif

<scalar-definition>
<array-definition>

../graphics/cbc2.gif

<scalar-definition>

variable-name

(format-length)

CONSTANT
INIT

init-definition [emhdpm]
HANDLE OF

dialog-element-type
OBJECT

(

A
U
B

) DYNAMIC

<array-definition>

variable-name

(format-length/array-definition)

CONSTANT
INIT

array-init-definition [emhdpm]
(array-definition) HANDLE OF

dialog-element-type
OBJECT

(

A
U
B

/array-definition) DYNAMIC

This document covers the following topics:

For an explanation of the symbols used in the syntax diagram, see Syntax Symbols.


Function

A variable-definition is used to define a single field/variable that may be single-valued (scalar) or multi-valued (array).

Syntax Description

Syntax Element Description
variable-name
Variable Name:

The name to be assigned to the variable. Rules for Natural variable names apply. With DEFINE DATA INDEPENDENT, the variable name must begin with a plus character (+).

For information on naming conventions for user-defined variables, see Naming Conventions for User-Defined Variables in Using Natural Studio.

format-length
Format/Length Definition:

For information on format/length definition of user-defined variables, see Format and Length of User-Defined Variables in the Programming Guide.

HANDLE OF OBJECT
Handle of Object:

Used in conjunction with NaturalX. A handle identifies a dialog element in code and is stored in handle variables.

The handle definition in the DEFINE DATA statement is generated automatically on the creation of a dialog element or dialog.

After having defined a handle, you can use the handle name in any statement to query, set or modify attribute values for the defined dialog-element-type.

Examples:

1 #SAVEAS-MENUITEM HANDLE OF MENUITEM
1 #OK-BUTTON (1:10) HANDLE OF PUSHBUTTON

For further information, see NaturalX in the Programming Guide.

HANDLE OF dialog-element-type
Dialog Element Type:

The type of dialog element. Its possible values are the values of the TYPE attribute.

For further information, see Dialogs and Dialog Elements in the Dialog Component Reference.

A, U or B
Data Type:

Alphanumeric (A), Unicode (U) or binary (B) for dynamic variables.

array-definition
Array Dimension Definition:

With an array-definition you define the lower and upper bounds of dimensions in an array-definition.

For further information, see Array Dimension Definition.

DYNAMIC
DYNAMIC Option:

A field may be defined as DYNAMIC.

For more information on processing dynamic variables, see Introduction to Dynamic Variables and Fields.

CONSTANT
CONSTANT Option:

The variable/array is to be treated as a named constant. The constant value(s) assigned will be used each time the variable/array is referenced. The value(s) assigned cannot be modified during program execution.

See also Defining Fields, User-Defined Constants, Defining Named Constants in the Programming Guide.

Notes:

  1. For reasons of internal handling, it is not allowed to mix variable definitions and constant definitions within one group definition; that is, a group may contain either variables only or constants only.
  2. The CONSTANT clause must not be used with DEFINE DATA INDEPENDENT and DEFINE DATA CONTEXT. The CONSTANT option cannot be used with X-arrays.
  3. The CONSTANT option must not be used with DEFINE DATA INDEPENDENT and DEFINE DATA CONTEXT.
INIT
INIT Option:

The variable/array is to be assigned an initial value. This value will also be used when this variable/array is referenced in a RESET INITIAL statement.

If no INIT specification is supplied, a field will be initialized with a default initial value depending on its format (see table Default Initial Values below).

For further information, see Defining Fields, Initial Values in the Programming Guide.

With DEFINE DATA INDEPENDENT and DEFINE DATA CONTEXT, the INIT clause is evaluated in each executed programming object that contains this clause (not only in the programming object that allocates the variable). This is different to the way the INIT works for global variables.
The INIT option cannot be used with X-arrays.

init-definition
Initial-Value Definition:

With the init-definition option, you define the initial/constant values for a variable. See Initial-Value Definition.

array-init-definition
Initial/Constant Values for an Array:

The array is to be assigned an initial value. This value will also be used when this array is referenced in a RESET INITIAL statement.

With an array-init-definition, you define the initial/constant values for an array.

For further information, see Initial/Constant Values for an Array.

emhdpm
EM, HD, PM Parameters for Field/Variable:

With this option, additional parameters to be in effect for a field/variable may be defined.

For further information, see EM, HD, PM Parameters for Field/Variable.

Default Initial Values

The following table shows the default initial values that are provided with the various formats:

Format Default Initial Value
B, F, I, N, P 0
A, U   (blank)
L FALSE
D D' '
T T'00:00:00'
C (AD=D)
GUI Handle NULL-HANDLE
Object Handle NULL-HANDLE

Fields declared as DYNAMIC do not have any initial value because their field length is zero by default.