Microsoft KB Archive/87717

{|
 * width="100%"|

WordBasic Error Using Caret for Exponentiation in Math Formula

 * }

Q87717

-

The information in this article applies to:


 * Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
 * Microsoft Word for Windows, versions 7.0, 7.0a

-

SUMMARY
If you use the caret character (^) to perform exponentiation in a Microsoft Word for Windows macro, the following error message is generated:

WordBasic Err=100

Syntax error

MORE INFORMATION
Page 31 of the &quot;Using WordBasic&quot; manual, written by WexTech Systems and Microsoft, documents exponentiation in mathematical formulas using the caret character within a WordBasic macro.

The example shown is as follows:

  CircleArea = pi*r^2 If you run a macro that contains this line, the WordBasic syntax error occurs. There is no supported mathematical operator in WordBASIC for exponential calculations.

For information, please see the following article in the Microsoft Knowledge Base:

"Q74050 Supported Mathematical Operators in WordBasic"

STATUS
This problem was corrected in Word 97.

WORKAROUND
To perform a mathematical calculation that involves exponents, you can use the ToolsCalculate function. This functions returns a value to a numeric variable. For example, to find the value of two to the eighth power (2^8), use the following WordBASIC statement:

x=ToolsCalculate(&quot;2^8&quot;)

-or-   Sub MAIN pi = 3.14159 x = ToolsCalculate(&quot;2^2&quot;) CircleArea = pi * x  Print circlearea End Sub The ToolsCalculate method does not accept variable names such as power and base. For example, the following macro results in a WordBasic bad parameter error:

 power = 8 base = 2 x = ToolsCalculate(&quot;base^power&quot;) The following macro example performs the sample calculation using variables:

 Sub MAIN power = 8 base = 2 result = 1 For count = 1 To power result = result * base Next Print result End Sub