Run-Time error 6 - Overflow

Run-Time error 6 - Overflow

Anonymous
Not applicable
1,356 Views
6 Replies
Message 1 of 7

Run-Time error 6 - Overflow

Anonymous
Not applicable
I have a VBA application that works fine in Windows NT. When I run it in Windows 95 or Windows XP I get an overflow error.

It appears to happen when I "Get" the property of a class I created and then do some math. A funny thing happened when I began debugging the problem. I wanted to know exactly which "Get" was causing the problem, so I introduced calls to msgbox before doing math calculations with the property values. The dumb thing worked without any errors.

Did slowing it down fix it? Or is something else at work here?

Below are portions of the affected code.

Class:DwgFile
Private m_ScaleFactor As Double
...
Public Property Get ScaleFactor() As Double
ScaleFactor = m_ScaleFactor
End Property
...

Class:Dwgs
Private m_data() As DwgFile
Private m_indx As Integer

Public Sub Add(FilName As String, filpath As String, sf As Double, dType As String, ByVal dSht As DwgSheet)
Dim aDwg As DwgFile
m_indx = m_indx + 1
ReDim Preserve m_data(m_indx)
Set aDwg = New DwgFile
aDwg.FileName = FilName
aDwg.FilePath = filpath
aDwg.ScaleFactor = sf
aDwg.DwgType = dType
Set aDwg.Sheet = dSht
Set m_data(m_indx) = aDwg
End Sub
Public Property Get Item(indx As Integer) As DwgFile
If indx < 0 Or indx > m_indx Then
MsgBox "Invalid index of DwgFiles object", vbCritical
Else
Set Item = m_data(indx)
End If
End Property
...

Calling Procedure:
...
'xref the files
For k = 0 To dwgs.Count - 1
If dwgs.Item(j).DwgType = detSHT Then
adrawing.ActivePViewport.Display True
adrawing.MSpace = True
sf = 1# / dwgs.Item(k).ScaleFactor
Else
MsgBox "Current Drawing: " & dwgs.Item(j).FileName
MsgBox "Numerator: " & dwgs.Item(k).ScaleFactor
MsgBox "Denominator: " & dwgs.Item(j).ScaleFactor
MsgBox "Formula : 1 / (" & dwgs.Item(k).ScaleFactor & "/" & dwgs.Item(j).ScaleFactor & ")"
'Error occurs below if msgbox calls are removed!
sf = 1# / (CDbl(dwgs.Item(k).ScaleFactor) / CDbl(dwgs.Item(j).ScaleFactor))
End If
If dwgs.Item(k).DwgType = detXREF And j <> k Then
fil = tb_path.Value & RenDwgs(k)
xref = Left(RenDwgs(k), Len(RenDwgs(k)) - 4)
Set XrefBlk = adrawing.ModelSpace.AttachExternalReference(fil, xref, _
insPT, sf, sf, sf, 0, True)
XrefBlk.Layer = aLayer.Name
If dwgs.Item(j).DwgType = detXREF Then
If k > 10 Then
clr = 41
Else
clr = colors(k)
End If
Call LyrColor(adrawing, xref, clr)
End If
End If
Next
...

I found similar posting from years ago, but the resolution was apparently accomplished via e-mail.
I'm stumped. Any help would be greatly appreciated.
0 Likes
1,357 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Are you running all of your tests on the exact same dataset? Sounds like a division by zero.
0 Likes
Message 3 of 7

Anonymous
Not applicable
Yes I am using the same data each time.

I have narrowed it down to this line:
sf = 1# / Cdbl(dwgs.Item(k).ScaleFactor) / Cdbl(dwgs.Item(j).ScaleFactor)

and this data:
sf = 1 / ( 4 / 48 )

4 / 48 = 0.083333 <- is that out of range?

1 / 0.083333 = 12 <- I know thats not out of range

Wahh!
0 Likes
Message 4 of 7

Anonymous
Not applicable
I found one problem, though it doesn't cause overflow on my computer... your code actually has sf = 1 / 4 / 48 === 0.00521, not 12. You need some more parentheses. What is sf dimensioned as? HTH, James
0 Likes
Message 5 of 7

Anonymous
Not applicable
For problems like this I prefer to go straight to the horses mouth to make sure I'm getting what I *think* I'm getting. Instead of using Message Boxes I would step trace the program to the line in question. Then with the yellow highlight on that line I would hold my mouse over each variable to see what value it currently holds. If anything doesn't show you it's value in a tooltip then highlight it and press Shift-F9 to see it in the Quick-Watch window.

Start with the simplest items like j and k, then progress to complex variables like dwgs.Item(j).ScaleFactor, then converted values like Cdbl(dwgs.Item(j).ScaleFactor), then logical groupings of values (in your case probably the entire expression). At some point the immediate values should squawk and you should be able to pinpoint your problem. If the entire expression is valid but it still fails on the assignment then it is something to do with your destination variable.

Regards

Wayne Ivory
IT Analyst Programmer
Wespine Industries Pty Ltd
0 Likes
Message 6 of 7

Anonymous
Not applicable
You're right of course. I should have cut and paste instead of re-typing it. I do have the extra parenthesis in the actual code. Thanks anyway!
0 Likes
Message 7 of 7

Anonymous
Not applicable
I haven't tried your suggestion(s) yet, but I will. I'm not as sophisticated with my debugging techniques as I would like to be. So, I will try what you suggest.

The reason I havn't tried yet is that I ran the program on another PC (a desktop) running Windows XP. It worked!

I now suspect that the problem could lie in the two laptops I was trying to test it on - one running Windows 95 and one running Windows XP - both the same hardware model - Compaq Pentium II 366 Mhz.

Go figure!
0 Likes