ID: Q76183
The information in this article applies to:
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 "# 6 Overflow Error."
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.
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" 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 "Number " + Str$(origvar) + " too large to Round"
End If
Print "Original ->" ; origvar ; " | Result -> " ; 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
"result= (newvar + Int((origvar * round) - newvar + 0.5))" 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 "Number " + Str$(origvar) + " too large to Round"
End If
Print "Original ->" ; origvar ; " | Result -> " ; result
End Sub
The following macro reproduces this error:
Sub MAIN
a = 100000
b = Int(a)
Print b
End Sub
"Microsoft Word for Windows Technical Reference," page 69
"Microsoft Word for Windows & OS/2 Technical Reference," pages 57-60, 209
Additional query words: vb vba vbe
Keywords : wordnt kbmacroexample ntword word6 winword2 word7 word95
Version : WINDOWS: 2.x 6.0 6.0a 6.0c 7.0 7.0a
Platform : WINDOWS
Last Reviewed: February 26, 1998