In DCAL you can work on different kinds of data. Each kind of data is of a different type. There are two main divisions among types. The first type is the Scalar Type. Scalar types are simple types; they are indivisible and cannot be reduced to any lower data form. The manual provides a complete listing of all scalar types.
We will only discuss the major types here. Refer to the manual for more information on other available types. While this is some dry reading it is important that you start to familiarize yourself with the different data types before we go on. Concentrate on the basics listed here then browse the manual for the other available types.
You will declare any types that you define yourself in a types section in your source code. We will cover user defined types when we cover advanced DCAL topics.
An integer is a whole number. It contains no decimal value. Valid integers in DCAL are numbers from -32768 to +32768.
A Boolean can only have two possible values, true or false. A Boolean is used in logical operations. If you have a background in another language such as C in which any positive value greater than zero is equivalent to true and a zero is false do not attempt to use these numbers where a Boolean is called for. DCAL will not recognize these conditions.
Real numbers are floating point numbers. They can have decimal values. The range allowable for valid real numbers in DCAL is +0.1E-63 to +0.999999E63 and -0.1E-63 to -0.999999E63. Real numbers cannot begin with the decimal point. You must start all real numbers with a number. Thus you would write 0.5 not .5.
A char is a single character. Values range from 0-255 and follow the standard ASCII character set. Characters must be enclosed in double quotes [ " ]. Do not use single quotes or they will be interpreted as strings.
A string is an array of characters. A string may be any length but you must declare the length of the string at the time of its use. For example:
test_str := string(40);
This is the declaration for a string that can hold a maximum of 40 characters. DCAL has several predefined types useful when working with strings. They are str8, str80, and str255. These provide for strings of 8, 80 and 255 characters respectively. For example:
test_str1 := string(80); test_str2 := str80;
are equivalent statements. Strings are enclosed in single quotes [ ' ].
A point is a record of reals. It is designed to hold the x, y, and z values of a point in 3D space. To access the individual x, y, or z values you need to use the notation:
x_value := pnt.x; y_value := pnt.y; z_value
where pnt is a variable of type point.
A file is a file on a disk. DCAL supports both binary and text files. The file name may also include the path to the file. If you need to access a file along a path be sure to use the correct format with regard to slashes. If you are using forward slashes use a single slash if you are using backslashes you must use two slash characters. For example:
A file type is essentially a string of a specific kind and in a specific format.
The entity type is the most complex type in all of DCAL. Refer to the chapter on types in the manual for the specific information on this type. An entity is any of the items that you can create within DataCAD. We will go into this type in greater depth when we cover entity creation.
There are many more types available to the DCAL programmer. We have only touched on the most basic ones.
The other 'kind' of type is the Array. An array is a method of grouping together a group of the same kind of data. An array is declared with the keyword ARRAY followed by a left bracket ( [ ) then the starting number of the array, two dots [ .. ] and the ending number of the array and the right bracket ( ] ) next is the keyword OF and the scalar type that the array is composed of. It sounds more complicated than it is. Here is an example:
fish : ARRAY [1..4] of str80;
What this says is we need 4 strings of 80 characters and they are all grouped under the name fish. This is equivalent to the following:
fish1, fish2, fish3, fish4 : str80;
It is often more convenient to place your data into an array. You will see why it is helpful as you go on. For now, just understand what an array is and that it is available to you.
To access the individual elements of the array you use their index. For example:
fish := 'trout'; fish := 'bass';
In this example we have placed two strings into the first two spots in the array. Notice the brackets are the same type as when we declared the array. The index is simply the number of the item in the array that we want to work with. Be careful to only use values that exist for your array. For instance, if you have an array declared as
number : ARRAY [1..10] of integer
and try to put something into
you will get errors. This sounds simple but as you will see later, when you use loops to work with arrays it is often easy to overstep the bounds of the array.
The last method of grouping data is the RECORD. We will only mention that it exists here. A record is a grouping of different types of data that for some reason need to be dealt with as one group. Lets say you want to setup a record type to describe a car. What sort of data might describe the car? Lets use color, horsepower and whether it is a convertible or not. We could set up a record that looks like this:
car = RECORD color : str80; hp : integer;
conv : boolean; END;
Do you see how we grouped three different scalar types under one record? This becomes handy later when we need to pass around this car in our code. Don't worry about records now except to know that they are available. We will cover records later as we learn more advanced ways to work with DCAL.