<< Click to Display Table of Contents >> Variables |
|
Variables are temporary storage locations where you can save information that can be accessed at a later time. Variables are useful for totaling field values across many records or within a group of records.
Variables actually consist of several components. Each variable must have a unique name. The variable name can be any combination of letters and numbers, but it is recommended that the variable be named something that describes the value it will hold. For example, if we are creating a variable that will hold the total of all sales, we might name the variable "TotalSale".
Each variable must also have a position indicator. The position indicator determines the order in which the variable is updated relative to the other variables in the variable list. This position can be very important when variables reference other variables. If our variable "TotalSale" references the variable "TotalTax" in its update expression, we must make sure that "TotalTax" has a position less than "TotalSale" so "TotalTax" will contain a meaningful value when it is accessed.
Each variable must also have an initial value. The variable is set to its initial value immediately prior to running the report and again during the report depending on the setting of the reset level.
The reset level determines when the variable is reset to its initial value. The variable can be reset at the report, section, page or group level. When the variable is reset at the report level, the variable is initialized immediately prior to running the report and is not reset until after the report has terminated. Use the report reset level to create variables that sum values for the entire report.
Variables that reset at the section level are initialized prior to the start of the section they are defined in. These variables are handy for creating totals for the section. If a report has only one section, these variables behave the same as variables that reset at the report level.
When a variable is reset at the page level, the variable is initialized prior to the start of each page. These variables are handy for creating page totals.
When a variable is reset at the group level, it is initialized prior to the start of each new group. Use the group reset levels to create variables which total on groupings.
The variable expression determines the value that is saved into the variable during the execution of the report. The variable expression is similar to the expression used in the Field object. Remember, the value returned by the expression you enter here is stored in the variable. If you define a variable which does not seem to contain the proper value, the expression is the first place to look.
Now that you know how to define a variable, how do you use it in a report? This is the easy part. When a variable name is referenced in an expression, the variable returns to the expression the value that it contains. Simply put, once you have defined a variable, you can include it in an expression.
Notice that variables you define are available in the Variables list box of the Expression Builder. The variables can now be selected and placed on the report in the same manor as a database field.