Declaration and Variable initialization |
Top Previous Next |
Variables consist of a name and a type: NameVAR := ….
Example 1: // String variable TextVar:= 'Welcome';
Example 2: // Integer type variable IntVar:= 16;
Example 3: // Hexadecimal variable(A16=1010) HexVar:=$A;
Example 4: // Char variable (65=A) CharVar:=#65;
Example 5: //Boolean variable initialized by an expression //that checks the file existence BoolFileExists:=FileExists('c:\customers.db');
The following example shows when the variable is used incorrectly. MyCustomer:='John Smith'; ... some code here ... // NOTE: The next line of script will cause a error! MyCustomer:=14;
The variable MyCustomer is initialized using text bounded by a single quote on each side: 'John Doe'. MyCustomer become a string type variable because it's first value is a string. If you try and replace the current value of MyCustomer with a integer type, the execution of that line of script will generate an error. However, MyCustomer can be assigned a new value of '14' because '14' is treated as a string type.
// This would OK MyCustomer:='14';
The error message displayed during the script execution will be: "Runtimeerror: Variable Name expects type ARRAY STRING instead of type ARRAY INTEGER [Position N] ".
|