Xbasic

# Operators in Xbasic

Description

Operators are used to write logical, arithmetic, character, date, time, and comparison expressions in Xbasic.

### Operator Precedence

A logical expression can include multiple comparison operations that are connected logically through the .AND. and .OR. operators. To control the order in which the expression is evaluated, use parentheses. Alpha Anywhere uses the following order of precedence when evaluating comparisons in logical expressions:

1. All arithmetic operations

2. Operations enclosed in parentheses

3. .NOT.

4. Substring inclusion (\$)

5. Relative and relative or equal (<=, >=, <, >)

6. Equal, Exactly Equal, Not Equal, and Not Exactly Equal (=, = =, <>, !=)

7. .AND.

8. .OR.

Including operators in order according to their precedence allows parenthesis to be implied when combining operations. For example, the expression:

`A >= 5 .AND. B = 10 .OR. A >= 50`

is equivalent to:

`(A >= 5 .AND. B = 10) .OR. A >= 50`

since the .AND. operator has precedence over the .OR. operator.When multiple operations have the same precedence, they are evaluated from left to right. For example:

```? .6 < 10 .AND. "Apple"="Apple" .AND. "Alpha" < "Beta"
= .T.```

### Using Operators

An operator is a symbol used to represent a mathematical, relational, logical, or string operation. For example, the asterisk (*) represents the mathematical operation of multiplication. Functions, field names, and constants can be combined with operators to form complex expressions. Most operators use the following syntax:

`expression operator expression`

Each data type (Character, Date, Logical, And Numeric) has a corresponding list of operators for combining multiple values of the same type together into a single value. The resulting data type is determined by the operator and the data type of its operands. There are several types of operators:

Operator Type
Resulting Data Type
Arithmetic

Numeric

Character

Character

Date

Date

Logical

All types

Comparison

All types

### Operators

Name
Description
Arithmetic Operators

Arithmetic operators are used between numeric expressions to yield numeric results. Alpha Anywhere supports the following arithmetic operators:

Character Operators

Character operators are used between character expressions to yield character results.

Date operators

Date operators are used to perform date and time addition and subtraction.

Logical Operators

Logical operators are used between logical expressions to yield logical results. See Also [Command Statements Reference]. Alpha Anywhere supports the following logical operators:

Comparison Operators

Comparison operators compare two expressions which must be of the same type (either character, numeric, or date) and will yield a logical result (i.e., TRUE or FALSE). Any expression involving a comparison operator is called a logical expression. Comparison operators are typically used in creating search criteria, filters, or are used with the IF and CASE functions. All comparison operators, except for substring inclusion, can evaluate numeric, date, or character values. For date values, earlier dates have lower values. For character values, the character's corresponding ASCII value is used in the comparison. Alpha Anywhere supports the following comparison operators:

\ (Backslash)

The backslash character "\" has several special functions within the Xbasic language. In the context of the Code Editor, it is used as a line continuation character or a backslash character. When used in the creation of an expression, it is used as an escape character or a backslash character.

: (Argument Designator)

Use arguments when you want to specify values in your SQL statement at run-time. You can include as many arguments in your SQL as you want. At run-time, if values have not been supplied for any of the arguments, Alpha Anywhere will display a dialog box prompting for argument values.

:: (Namespace Designator)

Basically a Namespace allows Alpha Anywhere to organize classes into logical "folders". You can think of the :: directive as much like a slash when you define a path. The Xbasicmodule class in Alpha Anywhere is stored in the type namespace. See also Xbasic Objects, Namespaces.

:= (Assignment Operator)

The := operator assigns a value to a variable. It can be distinguished from the = operator, which can be used to test equality.