Variables

Purpose

The language system's purpose is to help organize a solution to the problem. A basic need in getting organized is having a place to put things. Variables provide the places where information about the application is kept. The language provides simple variables, aggregate variable mechanisms (records types and object types) and arrays to help provide appropriate data structures to store information.

Fundamental Types

Variables come in different shapes and sizes (known as ?Types?) to accommodate the different shapes and sizes of information that you need to put somewhere. The fundamental types provided by Douloi Pascal include:

Boolean

Booleans are able to remember yes/no information. Boolean variables are helpful for decision related information and often have names such as

PartHasBeenRemoved
ProcessHasFinished
PointIsSelected

Integer

In this language integers are signed scalar numbers that have a range of -32767 to 32768. These are typically used for ?small? numbers and use 16 bits of storage for space efficiency. Integers are often used for iteration and quantities such as:

NumberOfPartsRemaining
DataBufferIndex
CurrentMotorTorque

Longint

Longint, or Long Integers, are 32 bit quantities and may have a range of about -4 billion to +4 billion. Longints are often used for position information expressed in counts (which can cover this range). Longints might have names such as:

RegistrationPosition
InputCapturePosition
DistanceToGo

String

Strings are variables which can contain letters and words. The language supports variable length strings with the default being 31 characters although other sizes can be indicated. Strings are null terminated. Examples of string variables names might include:

PartName
ErrorMessageText
LastRecordedCommand

Single Precision IEEE Floating Point Reals

Single precision reals are 32 bit variables which contain about 7 or 8 signficant digits of resolution over a range of 10^-37 to 10^38.

Double Precision IEEE Floating Point Reals

Double precision reals are 64 bit variables which contain about 15 or 16 significant digits of resolution over a range of 10^-307 to 10^308.

Usage

Variables are most easily used when given meaningful names and meaningful structure. A variable is made through a variable declaration. Most variables will be declared in plates with Snap2Motion:

The plate editor allows you to add, delete, and change variables with a dialog box and select the type you would like the variable to have from a list. You may also declare variables in procedures and functions for use locally within those procedures and functions using the ?var? statement. This statement has the form:

Variables may also be declared in procedures and functions for use locally within those procedures and functions using the ?var? statement. This statement has the form:

var : ;

After the word ?var? is a space followed by the name you would like to use for the variable. After the name (no space required) is a colon, and after the colon (no space required) is the variable type followed by a semicolon (which means ?end of statement?). Example variable declarations include:

var MoveDistance:longint;
var FirstTimeThroughProcedure:boolean;
var TorqueValue:integer;
var UserMessage:string;

Variable names must not have any spaces (although an underscore character may be used) and in general should only be composed of letter and numbers. Variable names may include numbers but may not begin with numbers.

Aggregate Types

Consider a ?desk organizer? in aesk drawer. A desk organizer contains various compartments for holding different types of things commonly found in a drawer such as paper clips, pencils etc. The desk organizer is a single, integrated item that has internal structure of various compartments, each compartment providing a suitable place for a particular aspect of its storage purpose. In a similar manner most high level programming languages allow the con- struction of such informational ?desk organizers?, data structures that contain ?compartments? where information can be stored while retaining a relationship with the whole. The language supports aggregate structures through Record and Object type declarations.

The creation of new Record and Object structures will be deferred until the Advanced Language section however the use of predefined record and object types will be reviewed here. Predefined aggregate types include examples such as:

T1Axis.............single axis of motion T2Axis.............2 coordinated axis of motion T3Axis.............3 coordinated axis of motion T4Axis.............4 coordinated axis of motion T5Axis.............5 coordinated axis of motion T6Axis.............6 coordinated axis of motion TButton............Windows Button Control (Snap2Motion only) TEdit..............Windows Edit Control (Snap2Motion only) TFile..............PC File (Snap2Motion only) TListBox...........List/Combo box control (Snap2Motion only) TPlate.............Assembly "Base" for applications TPrompter..........Modal dialog for operator (Snap2Motion only) TStatic............Output text/display (Snap2Motion only)

The first group are different types of coordinated axis groups and are collectively referred to as TNAxis. In actual usage the ?N? in TNAxis replaced with a number between 2 and 6 representing the dimension of the group.

A ?compartment? or ?field? of an object or record is indicated with a period after the variable name followed by the field name. The period indicates that the name following is specifically related to that variable. Field names can indicate component storage areas in an aggregate variable such as a record or object. Records contain only storage areas. Objects contain storage areas just like records and as well type specific procedures and functions which can operate on that information.

Objects and records are declared with the VAR keyword. A variable to represent a 2 axis positioning table could be declared with the command:

var PositioningTable:T2Axis;

This new variable named PositioningTable can be given commands. The first command necessary is an initialization command to associate that variable with actual axis in the system, for example:

PositioningTable.Init(XAxis,YAxis);

XAxis and YAxis are predefined variables of type T1Axis which correspond to the physical X and Y axis in the control system. Now the PositioningTable can be given a command to move, for example:

PositioningTable.SetMotor(On);
PositioningTable.MoveBy(20000,30000);

Detailed information about the predefined variables and operations can be found in the Command Reference.

The remaining types shown are for use specifically with Snap2Motion. Some of these types are declared graphically while others are declared with the ?var? keyword. In general these other types provide Windows components that can be manipulated by the application program to display information and product actions.

Arrays

Up until this point variables have been named symbolically and their access has been explicit on the part of the programmer. Arrays are a tool that give the program itself the ability to specify what storage area will be used to save information.

Arrays are linear arrangements of variables of a particular type. When referring to information in an array the name of the array is indicated as well as an index indicating which element is being used, for example the first one, or the third one. The location of the storage area of interest can be expressed numerically giving the program the ability to indicate a desired location. Arrays may be specified in Snap2Motion as plate variables through a dialog box such as shown below:

Any variable has the capacity to be part of an array. When defining a variable you can check the box indicating the variable represents an array and indicate the array bounds. The language allows the lower bounds and upper bounds of an array to be chosen. Note that the bounds may be symbolic constants.

Arrays of longints are frequently used as ?storage scope buffers? to collect position or information at the controller sample rate to be later plotted showing step response results or other information.

To create a variable array explicitly start with the VAR keyword and follow it with the name of the array. Following the name place a colon. Following the colon place the keyword array followed by a left square bracket, the lower bound either as a number of constant, two periods, the upper bound as a number of constant, a right square bracket, the word of and then the type of the array?s components followed by a semicolon. An example of an array declaration might be:

var DataBuffer:array[1..DataBufferSize] of longint;