Expressions 

BTC contains an expression parser that is used to evaluate the expressions allowed in: Expressions can range from a simple constant to an almost infinitely complex expression using the supported data types, operators, constants and variables.

Data Types

Supported data types are All supported Btrieve data types can be converted to/from one of these types.

Constants

The notation used to represent constant values for each of the supported data types are:
 
Data Type Description Examples
Integer One or more digits 623
Floating point Digits with decimal point. Scientific notation supported. 24.96 
2.998e8
String Any set of characters surrounded by double quotes. To place a double quote in the string constant it needs to be doubled. Also, any set of characters that don't starts with an alphabetic character and isn't a valid field name will be taken as a string value. "foobar"
Boolean There is no constant representation for a boolean value. A boolean value is always the result of a relational operator, a logical operator or a Logical type Btrieve field.  
Date The regular dd/mm/yy or dd/mm/yyyy notation is used but must be enclosed in single quotes as "/" is an operator itself (division). If a two digit year is given it will be assumed to be 21st century if it is less than 80. '1/11/98' 
'25/12/2001'
Time hh:mm[:ss][a|p] notation is used but, like dates, it must also be enclosed in single quotes as ":" is used in the conditional operator. '10:42p' 
'5:13:38'
 

Variables

The variables in a BTC expression are the names of the fields in the current file. When evaluated they take the value of the named field in the current record.

Operators

1. Relational Operators

These operators compare two values and return a boolean result (true or false). The two values must be of the same type with the one exception that integer and floating point values may be compared.
 
Operator Description Example
=
Equality: Returns TRUE of values are the same, FALSE otherwise.  CustomerName = "Fred Bloggs" 
Quantity = 5
!=
Not equal: Like = but gives the opposite result. CustomerCode != "CASH"
>
Greater Than: Returns true if the first value is greater than the second. Price > 20
<
Less Than: Returns true if the first value is less than the second. 20 < Price
>=
Greater Than or Equal: Returns true if the first value is greater than or equal to the second.  
<=
Less Than or Equal: Returns true if the first value is less than or equal to the second.  
== Same as = but string comparisons are case sensitive  
~=
Pattern Test: The left value is a string that is searched for a match to the regular expression in the right value. The regular expression can use any of the following wild cards: 
 
*
Substitutes for 0 or more characters of any value
?
Substitutes for 1 character of any value
[abc]
Substitutes for one character that has the value of one if the listed characters
{foo,bar}
Substitutes for one if the listed words
 
CustomerName ~= "*bob*" 
CustomerCode ~= "TRF*"
 

2. Logical Operators

These operators take boolean values and return a boolean result.
 
Operator Description Example
&
Logical AND: returns TRUE only if both values are TRUE Balance > 500 & CustomerCode != "CASH"
|
Logical OR: returns TRUE if either value is TRUE SellPrice < CostPrice | SellPrice < 5
!
Logical NOT: Returns the opposite logical value to the value it's applied to. !(ProductCode~="STD*")
 

3. Additive and Multiplicative Operators

These operators perform a calculation on two values and output a value of the same type. The two values must be of the same type except the case of an integer and a floating point value. In that case the result will be floating point.
 
Operator Description Example
+
Addition SellPrice < CostPrice + 10
-
Subtraction SellPrice - 10 < CostPrice
*
Multiplication SellPrice < CostPrice * 1.2
/
Division SellPrice / 1.2 < CostPrice
%
Modulus ReorderQty % 10 != 0
^
Power of KBytesNeeded * 2^10 < FreeSpace
 
 

4. The Conditional Operator

This operator, borrowed from the "C" language, returns either the second or third value depending on the first boolean value. The two alternative values must be of the same type. The syntax is:
x ? y : z

If x is true the value y is returned, otherwise the value z is returned.
EG.

SellPrice > 500 ? "Expensive" : "Cheap"

5. Brackets

Brackets can be used to override the normal order of operations as is standard in mathematical expressions.

6. Functions

Functions can be used to manipulate data in ways not provided by the standard operators listed above.