Expressions

An expression is a formula that can include either strings or numbers. A numeric expression consists of numbers or numeric variables linked together by operators to perform a mathematical calculation. For example, 2+2 is an expression.

WordBasic supports the following standard mathematical operators.

Operator

Function

+

Addition

Subtraction

*

Multiplication

/

Division

MOD

Modular division


The MOD operator performs a special type of division in which the whole-number part of the division result is discarded and the remainder is returned. For example, the result of 7 MOD 3 is 1 (1 is the remainder when you divide 7 by 3).

You can use just one mathematical operator — the plus sign (+) — in string expressions because, while it doesn't make sense to multiply, divide, or subtract strings, it's often useful to "add" or combine them. For example:


Word$ + " was found" + Str$(count) + " times in your document."

For more examples of combining strings, see "Some Sample Macros" at the end of this chapter. For detailed information on WordBasic operators, see "Operators and Predefined Bookmarks" in Part 2, "WordBasic Reference."