Overflow error 6

J

Jean-Guy Marcil

I have some complicated code that inserts a vertical bar in the left margin
at the cursor location. The bar matches the point height of the font at the
cursor location, or spans the selected range.

I have to calculate the range start and end; and, to ensure that the bar is
always at the same distance from the left margin, I also take into account
the section margin lay out.

Once in a while, I get an Overflow error 6 when running the code. There does
not seem to be any rhymes or reasons. The only thing I may say is that it
seems to happen if I rapidly use the code with various range lentghs.

The debugger always points to the same line in my code, even if I move the
statements around. It is a variable assignment line:

sngHeight = 0

I do not understand what is happening. How can assigning "0" to a Single
variable cause an Overflow?

Here is the start of the code:


Sub InsertVertLine()
Dim myShape As Shape
Dim sngHeight As Single
Dim sngDiff As Single
Dim rngCurrent As Range
Dim boolHeadFoot As Boolean
Dim sngModMargin As Single
Dim sngModMarginBottom As Single
Dim sngLeftMargin As Single
Dim sngAdjustVertPos As Single
Dim sngListIndent As Single
Dim sngConsLeftMargin
Dim boolMultiLine As Boolean
Dim boolRangeStartTable As Boolean
Dim lngStartPageNumber As Long
Dim sngFullLeftMargin As Single
Dim lngAlign As Long
Dim lngCellAlign As Long
Dim lngCharToUse As Long

Const sngABSConsLeftMargin As Single = 0.18
lngCharToUse = 1

boolHeadFoot = False
boolMultiLine = False
boolRangeStartTable = False
sngHeight = 0

Set rngCurrent = Selection.Range
lngAlign = rngCurrent.Paragraphs(1).Range.ParagraphFormat.Alignment ' = 0
Selection.Collapse wdCollapseStart
lngStartPageNumber = Selection.Information(wdActiveEndPageNumber)

With rngCurrent.Sections(1).PageSetup
'Check if we have mirrored margins, if so, more calculations are needed
If .MirrorMargins Then
'Add gutter size if necessary, if it exists and if we are on a even _
numbered page (Margins to left is an outside margin)
If Selection.Information(wdActiveEndAdjustedPageNumber) Mod 2 = 0 Then
'we have an outside (or right Margin)
'If margin is too narrow, the vertical bar will be too far to
the left. _
So we need to calculate a new standard position, which is
25% of the margin width.
sngFullLeftMargin = .RightMargin
If (sngFullLeftMargin) < 2 *
InchesToPoints(sngABSConsLeftMargin) Then
sngConsLeftMargin = PointsToInches((25 *
(sngFullLeftMargin)) / 100)
Else
sngConsLeftMargin = sngABSConsLeftMargin
End If
Else
'we have an inside (or left Margin)
'etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top