In esProc computing, we use constants frequently or sometimes store the data in the cellset directly. In this article, let’s learn the usage of constants in the esProc.
1. Directly using constant in the expressions
Constants can be directly used in the esProc expressions:
When constants are used in the expressions, the integer and the float can be used directly, but the string must be enclosed in quotes. For the Boolean constants true and false, they can be used directly in the expressions, but there are few cases of using them. The results in A1, A2 and A3 are as follows:
In particular, the capitalized L can be appended to the integer to indicate the long integer. Compared with the integer, the long integer has a wider range of value; the hexadecimal long integer can be represented with a string whose first two characters are 0x:
Because the value range of normal integers is -231~231-1, that is, -2147483648~2147483647, the result in A2 exceeds the value range of integer. In A1, a long integer is used, and the value range is increased to -263~263-1. By this way, the correct result can be obtained. The computed results in A1, A2 and A3 are as follows:
As can be noticed, during a certain step of the computation, if one of the operands involved in the integer computing is the long integer, the result is the long integer.
In a string used in an expression, if there are special characters like ” and \, an escape character \ is required as an indicator before each special character:
|2||=”\”I can come today,\” she said, \”but not tomorrow.\””|
After execution, the strings in A1 and A2 are as follows:
The time and date constants are not allowed in the expressions. Instead, only the type conversion functions, such as date(), time(), and datetime(), can be used to convert strings or long integers:
The result in A1 is as follows:
2. Constant cells
When the data is written to the cell directly, if the cell can interpret the string as a constant, then this cell can be regarded as a constant cell. Its cell value is the constant.
The default text in the constant cell is pink. Based on the data in the cell, the constant will be parsed into various data types. If the data is unidentifiable, it will be interpreted as a string.
The double quotation marks are not necessary when a string is defined in the constant cell.
In addition, in the constant cell, the constant can be represented as a percentage, like 5%:
After the computation, the cell values of A1 and A2 are as follows:
In the constant cell A1, 5% will be converted to the corresponding float value 0.05. Note: The writing style of 5% cannot be used in the expressions. It is only valid in the constant cells.
In particular, the value in the constant cell can also be true, false or null:
As can be seen from above, the constant cell value is the corresponding Boolean value or null value at this point:
The string constant cell can be used to specify the value of a cell as a string. The cell string in a string constant cell starts with the single quotation mark ‘ of English font. The string constant cell is used to define the strings containing special characters or those composed of figures:
In the above, the value of the constant cell A1 is the string abc\d; the cell value of A2 is the string 1234.5; the cell value of A3 is the number 1234.5:
In the constant string cells, the escape character \ is not necessary if any special character exists in the string:
|2||‘”I can come today,” she said, “but not tomorrow.”|
Values of strings in A1and A2 are as follows:
In a constant cell, we can also define the sequence constant with the brackets , and use commas to separate the sequence members. For example:
The sequence constants in A1 and A2 are as follows:
In defining a sequence constant, the double quotation marks are also unnecessary for indicating the string members in a sequence.
In an expression, we can use the cell name to reference the constant cell:
The result in A2 is as follows:
3. The sequence of constant cells
In esProc, once constants are saved in multiple cells, these cells are often combined to form a constant sequence for use in the expression. For example:
In A2, the expression [A1:F1] indicates a sequence composed of the values of all cells in the A1~F1 area. The sequence is as follows:
The cells in the sequence can also be in a continuous area:
In A3, expression [A1:C2] indicates a sequence composed of values of cells in an area from A1 to C2, and in which the members follow the order of first-row-then-column.
In esProc, an area of constant cells is often used to make up a TSeq:
In A5, a new TSeq is created. In A6, the record function is used to fill the TSeq with the values of the constant cells in the area of A1~E4.
With such method, the dfx file can be used to store the tabular data.