4 Data Variables and Data handling

Types and Forms of Variables

A variable describes a location in memory in which values can be stored. Computer languages use variable names to represent these locations. Then each time that variable name is quoted, the computer looks up the corresponding memory location and finds the value. The value contained within a variable may be altered, hence the name "variable". Each variable is of one type and holds a value of that type. For example:

A = 2 * B
Here A and B are variables. The number 2, of course, cannot be altered.

There are two main types of variables available with Eloquence--numeric and string. Numeric variables hold numbers, both positive and negative, integer or fractional. Numeric variables are themselves split into three types--INTEGER, SHORT and REAL. Numeric variables will be fully covered later in the chapter, but briefly:

A string variable can hold any sequence of ASCII characters. ASCII is the acronym for American Standard Code for Information Interchange. It is a standard way of representing characters and printing commands within a computer. A full list of ASCII characters is given in see chapter , ASCII Character Codes, in Appendix A. Note that an ASCII string is capable of holding all the keyboard type characters (including the blank character) and ASCII non-printing characters.

A feature of Eloquence is that strings may also include alternate character sets and display enhancements. These include such useful tools as line drawing characters and inverse video displays and are described fully in see chapter , Display Enhancement Codes/Character Set Switching Codes, in Appendix A. Use of alternate character sets will entail some added space overhead, as control bytes are added to the string.

A string may hold the characters 0 through 9. These are characters, not numbers. Arithmetic calculations cannot be performed on digits that are part of strings. Typical strings that contain digits not used in arithmetic calculations are strings holding addresses, part numbers, dates, and department codes.

Each type of variable, except the User Defined Types which can be of type simple only, can be declared in one of two forms--simple (non-subscripted) or array (subscripted). Each simple variable holds either one number (simple numeric variable) or a string of characters (simple string variable). An array variable is a collection of data items of the same type having from one to six dimensions. It is a convenient tool for handling large groups of data within a program.


The Eloquence language supports user defined data types. A user defined data type consists of a list of variables, called member variables. When a type is derived it inherits all properties (in this case, the member variables) of the base type. When you derive a type from a base type, you can use the derived type to call functions or subprograms which accept the base type.

Type definitions are inclosed in the TYPE .. END TYPE keywords. All variable declarations between will be part of the new data type.


The example below defines the data type Tphone, containing the member variables Id, Name$ and Phone$.

TYPE Tphone INTEGER Id DIM Name$[30],Phone$[20] END TYPE

The example below defines the data type Tphone2. Because it is derived from the type Tphone, it includes all member variables of the base type. It defines the new member variable Comment$.

TYPE Tphone2 EXTENDS Tphone DIM Comment$[40] END TYPE

There are different scopes (lifetimes) for type definitions:

If a type is defined globally (in the main program), it is available to all subprograms and functions. In addition, it will be passed to a program which is LOADed from the initial program. This is similar to COM variables. If defined in a SUB/FN program segment, a type definition is only known inside the subprogram. It will be deleted when the segment returns.


Eloquence Language Manual - 19 DEC 2002