Creating Variables

Crystal Report use parameters, because it defines the multiple values to a single object. If we change the values of any object, it stores the value, whenever we do not assign the next value.

If we define a variable in Crystal Report, first, we need to assign the different name, which does not match any other field like parameter name, report name etc. We know the variable holds the value of the single data at one point of time. We can use the variable as an array type, string type, data type, range type etc.

Defining a Variable

1

We can also assign any value to a variable. ‘Var’ keyword is used to declare the variable.

Syntax

This is the syntax to define any number and assign the value for it.

2

Scope of Variables

When we define variables, its scope is mandatory to be defined. The variables can be of following types, based on its scope,
  • Global
  • Local
  • Shared
Global Variables

We can use the value of a Global variable within all the report and also the sub reports. Global variable is used by the main report. It is not possible to define a global variable in a formula with the same name and the different formula. If we use global variable in our formula, use different type to define this.

3

Local Variables

Local variable is used only within the function, which means we can not access the value of the local variable into another formula. These are defined with the local keyword. Thus, the example of a local variable is,


4

Shared Variables

Shared variable is used like the global variable, but it is also used by the main part of the report. We use this in the sub reports. When we use the shared variable, it must define and assign its value. Now, we see an example of the shared variable,

5

Summary

Thus, we learnt that parameters helps to declare the multiple values of a single object. Hence, we use parameter in a Crystal Report.