Overview of Expressions

An expression is a user-defined reference to fields or other variables. When your data is displayed in a window or report, it is the result of evaluating an expression for the current record. In a query, a logical expression is used to compare the current record's fields to certain values. If you think this sounds like "programmer talk," you're right. AbacusLaw is ready to use out of the box, but it offers tremendous flexibility in letting you "re-program" it to behave just the way you want.

Expressions can be quite simple or very complex. Even novice users can select the fields to appear on a report without being overwhelmed with technical issues. At the same time, an expert user with a head for programming issues can get a wider range of results by combining several simple expressions into a complex one or by using special functions to look up or format data.

Simple Example

Here's an example of a simple expression that will return the last name from the current name record. This expression can be used in a report column expression, a quick form, or other places:

Last

Qualifying Field Names with an ALIAS

Since the same field name may appear in two databases (and for other important reasons), it is usually best to specify the database that contains the field. This removes any ambiguity. The database name is called an "alias" because it is not necessarily the name of the database file on disk. The primary aliases in Abacus are Names, Events, and Matters. To refer to a field explicitly, you enter the alias followed by an arrow (a hyphen and a greater-than sign) and then the field name. Following is another example of an expression, again asking for the last name field, but this time indicating which database to select from (this is the form you should usually use):

Names->Last

The alias and field name can be in upper case, lower case, or mixed case.

Both of the expression examples will return the contents of the last name field. If you entered "Surber" as the last name, both of these expressions will return "Surber" plus however many spaces fill out the field.

Types of Expressions

Just as fields can be different types (character, numeric, date, logical, etc.), expressions can be different types. Simple expressions have the same type as the field. More complex expressions always evaluate to a value that has a similar type.

Functions

A function is a program routine that can be included in an expression to manipulate data and return a value. Function names are NOT case-sensitive.

Function names are always followed by parentheses that may enclose one or more "parameters."

For example, trim("Surber ") will return "Surber" with no trailing spaces. The same is true for trim(Names->Last).

Click here for descriptions of some common functions in Abacus.

Date Functions

Date functions are functions specifically used for manipulating dates.

Click here for more information about date functions.

String Constants

"String" is another word for "character expression." "Constants" are expressions that don't change, like a simple number or a quoted string. So in the expression:

trim(Names->First) + " " + names->Last

there is a space character (string constant) that is added after the first name to separate it from the last name. You can use either double quotes or single quotes to enclose a string constant.

Combining/Adding/Concatenating Character Expressions

You can use the plus sign to add two or more fields (or other character expressions) to make a longer one, such as

trim(Names->Last) + ", " + names->First

This is essentially what the LastFirst() function does. It returns the last name followed by a comma and a single space, then followed by the first name. You can combine any number of character-type fields, functions, or constants in a character expression. Just be sure that each piece is of type character! For example, if you want a date field added after an event's What code, you must use a function to convert the date to a character string:

trim(Events->What) +" " + DToC(Events->When)

Logical Expressions

Logical expressions result in a value of True or False (in xBase expressions, these are represented by .T. and .F. ).

A logical type field, such as Active in the Names database, is a valid logical expression by itself. It is either True or False.

The most common logical expressions are queries. When you filter a database to see only certain types of records, the query expression is evaluated for each record. If it evaluates to True, the record is visible.

The Empty(xValue) function returns a logical value. It takes any type of value as its parameter and returns True (.T.) if that value is empty for its type.

For a numeric type, only zero returns .T.

For a character type, a value that is all spaces or that has no length returns .T.

The if(expressionL, expression1, expression2) function uses a logical expression to decide whether to return expression1 or expression2. For example, a user-defined screen might have a numeric field that needs to be validated as always greater than zero. In the field properties, the Valid expression might be:

if(Value > 0, .T., ErrBeep("Enter a value greater than 0.")

This if() expression returns .T. if the field's value is greater than zero (allowing the user to tab to another field). But if the value is 0 or negative, the second expression is evaluated instead. This takes advantage of the fact that the ErrBeep() function always returns .F. after popping up the enclosed message. When .F. is returned by a valid expression, the user is not allowed to exit the field.

Expressions in the VALID Field Property

When an operator enters data into a field and then presses TAB (or takes other actions to "leave" that field), the VALID expression for that field is evaluated. If it returns True, the operator can continue to other fields. If the expression returns False, the operator is not allowed to leave the field until a valid entry is made.

Click here for more information about expressions in the VALID field property.