WordBasic Error Using Caret for Exponentiation in Math Formula

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:
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("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

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

Keywords :
Version : WINDOWS:1.0,1.1,1.1a,2.0,2.0a,2.0a-CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0,7.0a
Platform : WINDOWS
Issue type :


Last Reviewed: December 23, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.