You can define variables in the report or label layout for storing, manipulating, and displaying values.
Report variables are PUBLIC in scope, and remain available after a report run (unless you explicitly specify that they should be released).
Defining report variables
To define a report variable
-
Open the report or label in the appropriate designer.
-
On the Report menu, click Variables.
The Report Properties dialog box opens.
Note: If the _REPORTBUILDER system variable is not set to the default Report Builder or is set to a third-party builder, the Report Variables dialog box displays or a different dialog box might display. For more information, see _REPORTBUILDER System Variable and Report Variables Dialog Box. -
In the Report Properties dialog box, click the Variables tab if it is not selected.
-
On the Variables tab, click Add.
-
In the Report Variable dialog box, type the name for the variable.
-
In the Value to store box, type an expression. At any given time during the report run, the variable will contain the evaluated results of the expression.
-
To specify an initial value for the variable, in the Initial value box, type an type an expression. The evaluated result of this expression will be assigned to the variable at the beginning of the report run..
Note: If you use the report variable in calculations, make sure to initialize the variable with a nonzero value to avoid a division-by-zero error. If you do not specify an initial value, Visual FoxPro assigns a default value of 0. -
To specify additional calculations to perform on the evaluated expression results prior to assigning a value to the variable, in the Calculation type list, select the calculation operation you want.
-
For cumulative calculation types, you can also specify the point at which the variable value is reset, by changing the setting of Reset value based on. For detailed information on calculation types, see Calculate Tab, Report Control Properties Dialog Box (Report Builder).
-
When you are finished, click OK.
You can now use the variable in your report or label.
For more information, see Variables Tab, Report Properties Dialog Box (Report Builder).
For example, consider a table of timesheet information with fields for punch-in and punch-out times stored in hour_in
, min_in
, hour_out
, and min_out
fields. The following table shows three example variables used in a report:
To store this value | Create this variable | Using this expression |
---|---|---|
Time employee arrived |
|
|
Time employee left |
|
|
Total time employee was present |
|
|
You can use the tDayTotal
variable in a variety of other calculations, such as the number of hours worked in a week, a month, or a year; the average number of hours worked each day; and so on.
For examples of report variables, see the sample reports Percent.frx and Invoice.frx in the Visual FoxPro ...\Samples\Solution\Reports directory.