Microsoft KB Archive/58984

IF Instruction Evaluated Incorrectly in Print Merge or Macro

PSS ID Number: Q58984 Article last modified on 11-02-1994

5.00 6.00

MS-DOS

= SUMMARY =

Using a conditional statement with an IF instruction in version 5.0 of Microsoft Word for MS-DOS may appear to produce an incorrect evaluation. A conditional statement consists of two expressions separated by a relational operator (=, >, <, and so forth) in the following format:

<>

If expression1 and expression2 are both variables that have been assigned numerical values by using either SET or ASK statements, the operator will evaluate the numbers as text (alphanumeric) values, rather than numerical values.

The following example demonstrates this evaluation:

<> <>

<smallnum>> PP <>

Note: The opening chevron (<<) is created by pressing CTRL+[. The closing chevron (>>) is created by pressing CTRL+].

The result is that “smallnum” evaluates as the larger number because the variables “bignum” and “smallnum” are being evaluated as alphanumeric values. The number 14 evaluates as smaller than 5, the expression is evaluated as false, and nothing is printed.

= MORE INFORMATION =

To work around this problem, perform a mathematical operation on the variables to force Word to recognize them as numerical values. Using the INT function or a mathematical operation (for example, multiply each variable by 1) will accomplish this. For example,

< INT(smallnum)>>

correctly evaluates “bignum” as the larger number.

Alphanumeric values are treated differently than numerical values; therefore, it may appear that the evaluation is incorrect.

Alphanumeric order evaluates as follows:

1 < 12 < 123 < 2 < 23 < 234 < 3 < 34 < 345 and so on.

Numeric order evaluates as follows:

1 < 2 < 3 < 12 < 23 < 34 < 123 < 234 < 345 and so on.

Version 4.0 of Word recognizes these variables as numeric and evaluates them as numeric values.

This problem was corrected in version 5.5 of Word for MS-DOS.

KBCategory: kbother kbmacro KBSubcategory: kbmerge Additional reference words: 4.00 5.00 5.50 ============================================================================= Copyright Microsoft Corporation 1994.