Datatypes and variables
|Top Previous Next|
Variables in a VPL program are used as placeholders for values. A variable can hold some kind of value. The type of value it can hold depends on the type of the variable. In VPL a number of data types exists. Various types are used for storing integer numbers, floating-point numbers and a type exists for storing text strings. It is even possible to make arrays of the simple data types - more on that in the ARRAY section.
When a program has variables of different types (which is usually the case), it is possible to use typecast to convert between the different data types. Please also see the section Typecast below for more information how to case between the various data types.
The VPL programming language offers a number of different data types.
The different data types are able to hold different types of data - be that integer numbers, floating-point numbers or strings. In a program, it is always best to try to select the smallest possible data type that is able to handle the given values. This will help reduce the space needed for the program. If, for example, one needs a variable with a value between 1 and 10, it is sufficient to declare a variable as the type SINT. On the other hand if mathematical expressions are to be handled a FLOAT needs to be used.
The complete list of the native data types are:
For declaring arrays of data, please have a look at:
Variables of different types cannot be assigned to one another when the destination is of different data type than the source. The VPL language contains a strong type-checking mechanisms, preventing errors when developing programs and the programmer is notified by syntax errors when trying to assign expressions to variables that are not of the correct type. In some cases, however, the programmer needs to assign expressions of the "wrong" type to variables, and because of that, typecasts are part of the VPL language. Typecasts are used to convert one type of expression to another type - for example if one wishes to convert a number to a BOOL variable. The BOOL type can only contain the values TRUE or FALSE, and it is therefore not possible to try to assign the value 1 or 0 (or any other number) to a variable of the type BOOL. If there is a need for such things, it is possible to use typecasting. The typecast is performed by writing the following:
var := TYPE(expression);
Here "var" is the destination variable, "TYPE" is one of the built-in data types, and "expression" is the expression that needs to be converted.