Export (0) Print
Expand All

About Operators

You can use operators in formulas to perform arithmetic operations (addition, subtraction, multiplication, and so on) or logical comparisons (greater than, less than, equal to, and so on). You also can control the order of evaluation in a formula by enclosing expressions in parentheses. Use the ampersand operator to combine (concatenate) character strings.

Microsoft Visio automatically attempts to convert data types when an operation or function requires a specific type of data. For example, the multiplication operator requires numeric arguments, and the ampersand (string concatenation) operator requires string arguments. If the argument cannot be converted to the required data type, a default value is provided. The default value is the typed equivalent of nothing: zero for numbers, FALSE for Boolean values, "" for strings, and so on.

The following table shows examples of expressions and their results.

Expression

Result

Description

2 * 5 & " cents"

"10 cents"

The & operator (string concatenation) requires string arguments, so the numeric result of 2 * 5 is automatically converted to the string "10".

5 * "2"

10

The * operator (multiplication) requires numeric arguments, so the string "2" is automatically converted to the equivalent number 2.

5 * "sheep"

0

The * operator (multiplication) requires numeric arguments, so because the string "sheep" cannot be converted to a number, zero is used as its numeric equivalent.

Arithmetic operators

Arithmetic operators perform operations on numbers. The plus (+) and minus (-) operators can be used alone as unary operators to establish the sign of a number. The percent (%) operator is also a unary operator and identifies the number as a percentage.

Operator

Action

Example

Result

+

Unary plus

+37

37

-

Unary minus

-37

-37

%

Unary percentage

37%

.37

^

Exponentiation

5 ^ 2

25

*

Multiplication

5 * 2

10

/

Division

5 / 2

2.5

+

Addition

5 + 2

7

-

Subtraction

5 - 2

3

Comparison operators

Comparison operators are used to construct logical expressions. A logical expression evaluates to either TRUE or FALSE.

Operator

Alternative

Action

Example

Result

>

_GT_

Greater than

5 > 2

TRUE

<

_LT_

Less than

5 < 2

FALSE

>=

_GE_

Greater than or equal to

5 >= 2

TRUE

<=

_LE_

Less than or equal to

5 <= 2

FALSE

=

_EQ_

Equal to

5 = 2

FALSE

<>

_NE_

Not equal to

5 <> 2

TRUE

The symbolic comparison operators (>, <, and so forth) are the best choice for most comparisons. The alternative operators (_GT_, _LT_, and so forth) perform an exact comparison to the full 15 digits of precision that Visio uses to store values internally.

When you compare rounded or calculated values by using the alternative operators, FALSE might be returned, when for all practical purposes the expression should evaluate to TRUE.

When you use comparison operators to compare text strings, the strings are first converted into numeric values. Text strings that cannot be converted return a value of 0; therefore, comparisons vary and might not produce the results you expect. To do a standard string comparison, use the function STRSAME or STRSAMEEX.

Order of evaluation

When a formula contains more than one expression, the expressions are evaluated in order according to the operation being performed. This table shows the order of evaluation of operators in Visio.

Order

Action

Operator

First

Positive

+ (unary)

Negative

- (unary)

Percent

% (unary)

Second

Exponentiation

^

Third

Multiplication

*

Division

/

Fourth

Addition

+

Subtraction

-

Fifth

String concatenation

&

Sixth

Greater than

> or GT

Greater than or equal to

>= or GE

Less than

< or LT

Less than or equal to

<= or LE

Seventh

Equal

= or EQ

Not equal

<> or NE

You can change the order of evaluation by enclosing expressions in parentheses. Visio evaluates expressions within parentheses first, from left to right. For example:

4 + 5 * 6 = 4 + 30 = 34

(4 + 5) * 6 = 9 * 6 = 54

If expressions in parentheses are nested, the expression in the innermost set of parentheses is evaluated first.

Ampersand operator

The ampersand operator returns a new character string. You can create compound words and phrases using the ampersand operator. Use the following syntax:

"string1" & "string2"

Example

"dog" & "house" returns "doghouse"

Show:
© 2014 Microsoft