Parameters and Variables

Read(2370) Label: parameter, variable,

esProc stores constants directly in cells, letting them to be referenced by cell names in expressions. For the basic uses of constants in esProc, please refer to Constants. Actually, when a constant value in a cell is referenced, the cell value is used as a variable. esProc allows any data types for parameters and variables and free conversion from one type to another, but you should be careful about the data type when calling them.

Here’s how to use the various parameters in esProc.

2.7.1 Cell parameters

For a cell having a value, esProc allows a calculation cell or an executable cell to reference the value by directly using the cell name. A cell with a value can be a constant cell, a calculation cell or any cell got assigned by an executable cell. A cell name is composed of the column letter and the row number. For example:

 

A

B

1

3

=3*5

2

=A1*B1

 

3

=B2

>B2=3.14

4

=B2/2

 

A1 is a constant cell, B1 contains an expression. Values of both can be used as parameters. The results of B1 and A2 are as follows:

 

There is neither a constant nor an expression in B2. So when A3 calls B2, the result is null. In fact the initial value of any cell is null.

B3 sets value for cell B2. So when B2 is called in A4, its value becomes 3.14. The result of A4 is as follows:

It can be seen that if a cell’s value is not null, the background will be light yellow by default.

In esProc, you can directly use a cell parameter without declaring it in advance or defining the parameter name. The cell parameters are also easy to look up. Therefore they have been widely used.

The following program, for example, uses cell parameters to store and compute the accumulated value:

 

A

B

C

1

=demo.query("select * from CITIES")

 

 

2

 

 

 

3

for A1

if A3.POPULATION>500000

>A2=A2+1

4

 

else

>B2=B2+1

A3 traverses the data of cities. If a city’s population is greater than 500,000, it will be counted in A2; otherwise it will be counted in B2. After computation, the results of A2 and B2 are as follows:

 

2.7.2 Program parameters

In a cellset file, you can also define the program parameters, which can be used only in the current cellset.

Click Parameter in the Program menu item on the menu bar, and you can view the settings of program parameters:

You can set the parameters used in a cellset file in the Program parameter dialog box. A program parameter name is not allowed to contain spaces and signs, and include numbers alone; the parameter value, which can be a constant of any data type, will be automatically parsed into corresponding data type. Please note that expressions cannot be used as program parameters.

If the Set arguments before running option is checked, the Input argument window will pop up before the cellset file is computed:

You can modify the program parameter value before computation starts, or use the default value. To use a program parameter, call it directly by its name:

 

A

1

=pi*4

2

=arg1+" world!"

3

=arg2.(~*~)

After computation finishes, the results of A1, A2 and A3 are respectively as follows:

   

A program parameter should be defined before it is used. The use of an undefined program parameter in an expression will make the expression unable to be parsed and thus cause an error.

Since the names of program parameters are user-defined, they are often used to store some computational constants, such as Pi. In addition, program parameters are used to set the data that needs to get assigned before the computation begins. For example:

 

A

B

C

D

1

Big

Small

SAME

 

2

 

 

 

 

3

for num

=rand(6)+1

=rand(6)+1

=rand(6)+1

4

 

if B3==C3 && B3==D3

>C2+=1

 

5

 

else if B3+C3+D3>10

>A2+=1

 

num is a predefined program parameter for setting the number of throwing dices. The computing goal is to count the points of 3 random dices. If the total point is greater than 10, mark it as big and store it in A2; if the total point is less than or equal to 10, mark it as small and store it in B2; if the 3 dices have the same points, store this throwing in C2 without marking it as big or small. Now set num as 100 and perform the computation, results of A2, B2 and C2 are as follows:

   

In the cellset, the expression >C2+=1 is equal to >C2=C2+1. For expressions like a=a?x, they can be abbreviated to a?=x.  

2.7.3 Cellset variables

The definition

Besides using cell names directly and calling predefined program parameters, you can also use variables that have specified names. They are called cellset variables. Cellset variables are automatically created through value assignment, without having to be declared in advance, and are valid across the whole cellset. But the reference of an unassigned variable will cause errors. For example:

 

A

B

1

>a=5

>b=[1,3,2]

2

=a+3

=b.(~+a)

A1 and B1 define cellset variables a and b respectively to be called from A2 and B2. After computation, the results of A2 and B2 are as follows:

 

The cellset variables that are already defined and their values can be viewed in page Cellset variable in the bottom right of the interface:

The program parameters defined by the cellset program will also be displayed in this list. 

Judging variables

esProc uses ifv function to check if a variable has been defined. For example:

 

A

B

1

>a=5

>b=[1,3,2]

2

 

 

3

if ifv(a)

>A2=b.(~+a)

4

else

>B2=b

The third and fourth lines of code assign values to A2 and B2 respectively. Only A2 has result:

B2 is empty. 

2.7.4 Cellset constants

You can set parameters used repeatedly in the cellset as the cellset constants, which are used in the same way as the program parameters, that is, calling them by their names. But the cellset constants are different from the program parameters in that you can set data types for them but are not allowed to assign values to them in a cellset, while the program parameters can get assigned.

To view the cellset constants, you can click the Cellset constant button on the Tool menu:

A constant can be of any data type, such as string, integer, date and sequence, etc. You can directly call it by its name for use:

 

A

1

=param1+" Smith"

2

=round(pi*3*3, 2)

3

=param2.sum()

After computation the results of A1, A2 and A3 are as follows:

   

2.7.5 Prioritizing parameters, variables and constants

The above explains the uses of cell parameters, program parameters, cellset variables and cellset constants. But how should you handle the situation where parameters, variables or constants exist at the same time?

In the following situation, pi is set as both the cellset constant and the program parameter:

By doing so, the cellset is as follows:

 

A

1

=pi

2

>pi=3

3

=pi

After computation, the results in A1 and A3 are as follows:

 

As can be seen, when the namesake cellset constant and program parameter are defined at the same time, the latter has the priority. That’s why the value of A1 is 3.14. But if there is a cellset variable of the same name in the cellset, this cellset variable gets the priority. Therefore the value of A3 is 3 assigned by A2.

Another situation:

 

A

1

 

2

=A1

3

>A1=3

4

=A1

As there is no data in A1 originally, the result of A2 is empty. That’s also because the "A1" defined as a program parameter cannot be identified. So you shouldn’t use cell names when setting program parameters.

After A3 assigns value to "A1", the background of cell A1 becomes light yellow. But in the bottom right of the interface there isn’t such a cellset variable as "A1", which means A3 has actually assigned the value to the cell. Now both A1 and A4 have the same data:

 

Hence, in esProc you should avoid using cell names when defining the program parameters, cellset constants and cellset variables.