9.4 Expressions and Conditions

Before we can go on to talk about other statements, we must first discuss what expressions and conditions are. An expression describes a numerical quantity. Most standard numerical operators are supported by the Report Writer. Due to the type-less nature of the language, automatic type conversions make forming expressions extremely easy. As an example: suppose you want to figure out how much to bill someone for their subscription. To do this, you have a dollar price per year which you multiply by the number of years to produce the total subscription cost. In the Report Writer this expression is:

year_rate * issues

Since year_rate is a MONEY value, the result of the expression is a MONEY value. If you multiply two money values together, such as a balance owed and the yearly rate, the Report Writer does the multiplication; however, this type of expression has no meaning so the Report Writer changes the type of the expression to REAL. Again, the type conversions are done to make the expressions seem natural. Thus a DATE plus or minus a number yields another DATE, MONEY times or divided by a number yields more MONEY, and a DATE subtracted from another DATE yields the number of days between the two DATEs.

A condition describes some kind of decision to be made. Conditions may contain logical relations between expressions (is expression1 greater than expression2?). They may also contain logical combinations of other relations (is expression1 equal to expression2 and expression3 less than expression4?). It is possible for a condition to contain just an expression. In all cases, the condition is evaluated, and if the result of the condition is non-zero, the condition is said to be true. If the result is zero, the condition is false.

The following table describes the logical operators that are available in Report Writer. Each operator has two forms. You may use either form.

Form1 Form2 Description

EQ = condition 1 is equal to condition 2

NE != condition 1 is not equal to condition 2

LE <= condition 1 is less than or equal to condition 2

LT < condition 1 is less than condition 2

GE >= condition 1 is greater than or equal to condition 2

GT > condition 1 is greater than condition 2

OR | condition 1 inclusive or'd with condition 2

AND & condition 1 and'd with condition 2

It is impossible to show all of the possible combinations of conditions that can be formed by the programmer. Most of this is due to the type-less nature of the language. For example, if you were going to compare a field against some value you could use the following conditions:

balance LE "10.00"

balance <= 10

balance <= 10.00

10 GT balance

Any of these examples would check for a money balance that was less than or equal to ten dollars. Because of this great variety, we will show only some of the more common conditions and let you do some exploring to find the others.

For the most part, conditions are evaluated in such a way as to make the condition seem natural. For instance, to check that a starting subscription date is within the year 1983, you can write:

started GE "01/01/83" AND started LE "12/31/83"

Or, to find all subscriptions that have been started within 30 days of the current day you could write:

$todays_date - started LE 30

started + 30 GE $todays_date

In the first condition, you are checking to see if the current date and the starting date differ by fewer than 30 days. In the second condition, you are checking to see if 30 days from the starting date is still beyond the current date. In either condition, the result is true if the starting date is within 30 days of the current date.