baserunner
contents    queries
configuration templates
expressions sessions
databases data entry
passwords email
license support

Expressions

Data display expressions
Date entry expressions
Query and conditional display expressions
Data sorting expressions
Building expressions
Expression constants
Numeric operators
Character operators
Relational operators
Logical operators
Expression functions

baserunner makes extensive use of xBase style expressions. Expressions are used to display data, to construct queries, to sort data, to enter and edit data, and to conditionally display data. Expressions return a value of a specific type. This type can be numeric, character (text), date, or logical (the same as the xBase field types).

Expressions consist of constants, operators, field values, and functions.  The most common form of expression is the name of a field. In this case, the type of the expression is the type of the field. Field names, constants, and functions may all be combined to form expressions. Note that expressions passed on the command line should be URL encoded.

Data display expressions

An expression used within a tag in a template will be be replaced by the character value returned by the expression.

A character or memo field can be added simply by using the name of the field as the expression. With memo fields, this is all you need, since memo fields are automatically trimmed. Note that if you will be using longer memo fields, you may need to set the _memolength variable in your configuration file.

With character fields, you will usually want to use either the TRIM() or the ALLTRIM() function.

{text_field}
{trim(text_field)}
{alltrim(text_field)}

If you don't use one of these functions, the output of the field will be the same length as the field itself (i.e. if a 25 character field contains the string "test", without one of the trim functions, the output would be "test                     ".)

Numeric fields are displayed as strings by using the STR() function:

{str(numeric_field,10,2)}

This would display up to 10 digits with 2 decimal places. STR() may be combined with LTRIM() to eliminate any leading blanks:

{ltrim(str(numeric_field))}

Date fields are displayed using the DTOC() function:

{dtoc(date_field)}

This function formats the date according to the _dateformat variable in the configuration file.

Logical fields may be displayed using almost any format with the conditional IIF() function (or with a conditional display directive):

{iif(logic_field=.T.,'true ','false')}

If the field is true, the output will be the string "true"; if it is not true, the output will be the string "false". The output specified may be any string, and may be used to modify HTML code, e.g:

<form>
<input type="checkbox"
{IIF(logic_field=.T.,'checked','        ')}>
</form>

This example shows a checkbox. If the value of the field is true, the box is checked; otherwise it is empty. When using a form field to display data, it is important that you wrap the display in <form></form> tags. Internet Explorer displays form fields that occur outside of forms just fine (even though it is not legal HTML) Netscape is not so forgiving.

Beyond simply displaying data as it is recorded in the database, you may use any expression that returns a character value including, for example, substrings, or the results of numeric and date formulas.

Data entry expressions

When you use an expression to add data to a field (using a form variable named %fieldname), the return type must be the same as the field type. In other words, logical fields need an expression that returns a logical type, date fields need an expression that returns a date type, numeric fields need an expression that returns a numeric type, and character and memo fields need an expression that returns a character type.

Data sorting expressions

An expression used to sort data may return any type except logical.

Query and conditional display expressions

Expression used to create queries or to conditionally display data must return a logical value. In both cases the results of the expression are evaluated to determine whether or not to include a particular record. Most often, these expressions will consist of some constant, a relational operator, and a field value. The constant is compared to the field value using the operator. The result is either .T. or .F.

chr_field="value"
"value"$mem_field
num_field=VAL("123")
num_field>=VAL("123")
dat_field=CTOD("01/15/1960")
log_field=.F.

Building expressions

Expressions are built from elements including constants, operators, field values, and functions. baserunner supports most standard xBase language constructions.

Expression constants

Constants within expressions can consist of a Numeric, Date, Character or Logical values. Constants are usually used within a more complicated expression, by themselves, they really aren’t of much use.

A Numeric constant is a number.

A Date constant is a date value in the native CCYYMMDD format.

Character constants are letters or digits enclosed in single or double quotation marks. If you wish to specify a character constant with a single quote or a double quote contained inside it, use the other type of quote to mark the character constant.

.TRUE. and .FALSE. are the logical constants. .T. and .F. may be used as abbreviations.

Numeric operators

Add + Divide /
Subtract - Exponent **
^
Multiply *    

The numeric operators operate on any numeric values. Numeric values may be given as field names or as constants, i.e. (12 + 4) will return 16, (price * 1.04) will return the value found in the numeric field price times 1.04. When you use more complex expression, use brackets to make the evaluation order explicit: e.g. ((1+2)*3) rather than (1+2 *3).

Character operators

Concatenate 1 +
Concatenate 2 -

These two character operators concatenate (combine) character values, either constants or field values. Using "+" retains any whitespace present at the end of the first value, e.g. ("John " + "Smith") returns "John Smith"; using "-" moves any whitespace at the end of the first value to the end of the returned value, e.g. ("John " – "Smith") returns "JohnSmith "

Relational operators

Equal to = Less than or equal to <=
Not equal to <> or # Greater than or equal to >=
Less than < Contained in $
Greater than >    

The relational operators return a logical result (either true or false). All relational operators, except Contain, operate on Numeric, Character or Date values. Contain operates on two character values and returns true if the first is contained in the second.

Logical operators

Logical and .AND.
Logical or .OR.
Logical not .NOT.

The logical operators, operate on two logical values and return a logical result.

Expression functions

A function can be used as an xBase expression or as part of an xBase expression. Functions return a particular type of value like operators, constants and fields.

Function Returns About
ALLTRIM(char_value) Character This function trims all of the blanks from both the beginning and the end of the character string.
ASCEND(value) Special This function is really only useful for setting the sort order for the database. This function causes the records to be sorted in ascending order.
CHR(integer_value) Character This function returns the character whose numeric ASCII code is the given integer. The integer must be between 0 and 255.
CTOD(char_value) Date The character to date function converts a character value into a date value. The character representation is always in the format specified by the _dateformat variable in the configuration file.
DATE() Date The system date is returned. Date arithmetic may be done using this (or any date) value. For example, DATE()+10 is the date ten days from the current date.
DAY(date_value) Numeric Returns the day of the date parameter as a numeric value from "1" to "31".
DELETED() Logical Returns .TRUE. if the current record is marked for deletion.
DESCEND(value) Special This function is really only useful for setting the sort order for the database. This function causes the records to be sorted in descending order.
DTOC(date_value) Character The date to character function converts a date value into a character value. The format of the resulting character value is specified by the _dateformat variable in the configuration file.
DTOS(date_value) Character The date to string function converts a date value into a character value. The format of the resulting character value is "CCYYMMDD". (The native xBase format).
IIF(logical_value, true_result, false_result) Character If 'logical_value' is .TRUE. then IIF returns the 'true_result' value. Otherwise, IIF returns the 'false_result' value. Both true_result and false_result must be the same length and type.  Logical_value may be any expression that returns true or false: a logical field value (field=.T.); or an expression "'Smith'$char_field", "num_field<=10", etc.
LEFT(char_value, num_chars) Character This function returns a specified number of characters from a character expression, beginning at the first character on the left.
LTRIM(char_value) Character This function trims any blanks from the beginning of the expression. This function is useful when displaying numeric fields. A numeric field that contains fewer digits than the field length will be padded with spaces. Of course, such padding makes it easier to line up columns of numbers.
MONTH(date_value) Numeric Returns the month (1-12) of the date parameter as a Numeric.
RECCOUNT() Numeric The record count function returns the total number of records in the database.
RECNO() Numeric The record number function returns the record number of the current record
STOD(char_value) Date The string to date function converts a character value into a date value. The character representation is in the format "CCYYMMDD"
STR(number, length, decimals) Character The string function converts a numeric value into a character value. "length" is the number of characters in the new string, including the decimal point. "decimals" is the number of decimal places desired. If the number is too big for the allotted space, *'s will be returned. This function should always be used to display a numeric value.
SUBSTR(char_value, start_position, num_chars) Character A substring of the character value is returned. The substring will be 'num_chars' long, starting at the 'start_position'.
TIME() Character The time function returns the system time as a character representation. It uses the following format: HH:MM:SS.
TRIM(char_value) Character This function trims any blanks off the end of the character string.
UPPER(char_value) Character A character string is converted to uppercase and the result is returned.
VAL(char_value) Numeric The value function converts a character value to a numeric value.
YEAR(date_value) Numeric Returns the 4 digit year of the date parameter as a numeric value.

 


Copyright © 1998-99 baserunner Software (Mark Glover)