DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

# DBASE Expression Operators

//Operators like '+' , ' * ', or '<' are used to manipulate constants and fields. //For example, "3+8" is an example of a dBASE expression in which the //Add operator acts on two numeric constants to return the numeric value //"11". //The values an operator acts on must have a type appropriate for the //operator. For example, the divide '/' operator acts on two numeric values. //Precedence //Operators have a precedence which specifies operator evaluation order. //The precedence of each operator is specified in the following tables which //describe the various operators. The higher the precedence, the earlier the //operation will be performed. For example, 'divide' has a precedence of 6 //and 'plus' has a precedence of 5 which means 'divide' is evaluated before //'plus'. Consequently, "1+4/2" is "3". //Evaluation order can be made explicit by using brackets. For example, //"1+2 * 3" returns "7" and "(1+2) * 3" returns "9". Numeric Operators The numeric operators all operate on Numeric values. Operator Name Symbol Precedence Add + 5 Subtract - 5 Multiply * 6 Divide / 6 Exponent ** or ^ 7 Character Operators There are two character operators, named "Concatenate I" and "Concatenate II", which combine two character values into one. They are distinguished from the Add and Subtract operators by the types of the values they operate on. Operator Name Symbol Precedence Concatenate I + 5 Concatenate II - 5 Examples: " 'John ' + 'Smith' " becomes " 'John Smith' " " 'ABC' + 'DEF' " becomes " 'ABCDEF' " Concatenate II is slightly different as any spaces at the end of the first Character values are moved to the end of the result. " 'John'-'Smith ' " becomes " 'JohnSmith ' " " 'ABC' - 'DEF' " becomes " 'ABCDEF' " " 'A ' - 'D ' " becomes " 'AD ' " Relational Operators Relational Operators are operators which return a Logical result (which is either true or false). All 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. Operator Name Symbol Precedence Equal To = 4 Not Equal To <> or # 4 Less Than < 4 Greater Than > 4 Less Than or Equal To < = 4 Greater Than or Equal To > = 4 Contain $ 4 Examples: " 'CD' $ 'ABCD' " returns ".T." " 8<7 " returns ".F." Logical Operators Logical Operators return a Logical Result and operate on two Logical values. Operator Name Symbol Precedence Not .NOT. 3 And .AND. 2 Or .OR. 1 Examples: " .NOT. .T. " returns ".F." " .T. .AND. .F." returns ".F."