WordBasic Error Using Caret for Exponentiation in Math Formula

Last reviewed: July 30, 1997
Article ID: 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 95, 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 "Using WordBasic" 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:

   ARTICLE-ID: Q74050
   TITLE     : 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("2^8")

 -or-

   Sub MAIN
   pi = 3.14159
   x = ToolsCalculate("2^2")
   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("base^power")

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

REFERENCES

"Using WordBasic," by WexTech Systems and Microsoft, page 31

"Microsoft Word Developer's Tools Forum," page 113 (from the Macro Developers Kit)

Kbcategory: kbusage kbmacro KBSubcategory:


Additional query words: 2.0 2.0a 2.0a-CD 2.0b winword word6
winword 7.0 word95 word7 docerr doc err exponent exponentiate power
calculate mdk winword2 6.0
ToolsCalculate

Version : 2.x 6.0 6.0a 6.0c 7.0 7.0a
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.