You are here: Automating Analyzer > Variables > Using Variables

Using Variables

There are four principal uses for variables:

To specify constants for use in an application, such as a sampling interval
To provide special information to Analyzer, such as automatic page headers and margins
In applications such as Group commands, to retain information from previous records or for other control purposes
To provide dynamic lists for Dialog commands. For more information see Manually Editing Dialog Commands and Variables.

There are many other possibilities for using variables that you will quickly discover as you begin using them for yourself.

Note: When accumulating information in a Group command for subsequent extraction or other command processing that is triggered when key values change or the end of file is reached (see EOF), it is mandatory that you store all required field and key information in variables to ensure that it is available to be processed when the command is triggered.

Constants

A variable can hold the value of a constant. For example, you can use a variable to record the materiality level that is used in determining sampling intervals. You can refer to the variable rather than the materiality value throughout your procedures. In this way, if the materiality changes, you need to change only the variable value to alter all of your samples accordingly.

Parameters

Variables are also useful for holding parameters. The random starting value for a sample can be entered as a variable parameter. Parameters are often entered into procedures using the Accept command, which allows for a procedure in which commands remain the same and only the values of the variables change as different parameters are required.

Macros

You can substitute a value into a command using a special type of variable: a macro. For more information, see Macro Substitution.

Previous Record Contents

Using variables to store the contents of previous records can be very effective when processing multiple-record-type files. Because the contents of data fields change every time you move to a new record, you can assign the information to a variable if you want to retain it as other records are processed. or more information, see Multiple-Record-Type Files. See also Groups for information on processing multiple-record-type files.

Ongoing Calculations

In some cases, you may want to perform calculations that span a number of records or perhaps even an entire file. For example, you can use variables for totalling the detail amounts in an invoice and subsequently ensuring that the invoice total agrees with the sum of the details. As well, if you want a running total throughout a file, you can use a variable and update it with the contents of every record.