Microsoft KB Archive/76183

{|
 * width="100%"|

WD: Int Function Limitations and Workaround

 * }

Q76183

-

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
In Microsoft Word for Windows versions 1.x, 2.x, 6.x, the Int WordBasic function is limited to working with values less than 32,769. If you use a value greater than 32,769, Word returns the WordBasic error message &quot;# 6 Overflow Error.&quot;

In Word 7.x, you can exceed the Int limit of 32,768 up to 99,999,999,999,999 without Word converting it to scientific notation.

There is a documentation error in Word 7.x Help indicating that 32,768 is still the limit.

Note: In Word 97 Visual Basic for Applications, you can exceed the WordBasic Int limit of 32,768 up to 999,999,999,999,999 without converting it to scientific notation.

WordBasic
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code &quot;as is&quot; without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

The following is an example of a rounding function that rounds to whole numbers, tenths (1/10), or hundredths (1/100) by specifying the round variable:

  Sub MAIN origvar = 1102540.126456 round = 100 ' To round to nearest Integer       Tenths           Hundredths 'Round =                1             10                 100 'Round to               0            0.1                0.01 'Limitation     1,073,741,824    107,374,182.4     10,737,418.24 If origvar <=( 32768 * 32768) / round Then newvar = Int((origvar * round) / 32768) * 32768 result =(newvar + Int((origvar * round) - newvar + 0.5)) / round Else MsgBox &quot;Number &quot; + Str$(origvar) + &quot; too large to Round&quot; End If     Print &quot;Original ->&quot; ; origvar ; &quot; |     Result -> &quot; ; result End Sub To round to the nearest whole number, the function is simplified to eliminate the round variable from the macro above. The + 0.5 in the line &quot;result= (newvar + Int((origvar * round) - newvar + 0.5))&quot; can be removed if you only want the integer part of the number to be returned.

  Sub MAIN origvar = 1100000000.12646 'Limitation                  1,073,741,824 If origvar <=( 32768 * 32768) Then newvar = Int((origvar) / 32768) * 32768 result =(newvar + Int((origvar) - newvar + 0.5)) Else MsgBox &quot;Number &quot; + Str$(origvar) + &quot; too large to Round&quot; End If     Print &quot;Original ->&quot; ; origvar ; &quot; |     Result -> &quot; ; result End Sub The following macro reproduces this error:

  Sub MAIN a = 100000 b = Int(a) Print b  End Sub