Compartir a través de


How to: Define Report Variables

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

  1. Open the report or label in the appropriate designer.

  2. 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.

  3. In the Report Properties dialog box, click the Variables tab if it is not selected.

  4. On the Variables tab, click Add.

  5. In the Report Variable dialog box, type the name for the variable.

  6. 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.

  7. 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.

  8. 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.

  9. 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).

  10. 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

tArrive

hour_in + (min_in / 60)

Time employee left

tLeave

hour_out + (min_out / 60)

Total time employee was present

tDayTotal

tLeave - tArrive

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.

See Also

Tasks

How to: Open Reports and Labels

How to: Change Report Variable Order

How to: Reset Report Variables

Other Resources

Working with Report Variables