Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run Time Error 6 Overflow

Status
Not open for further replies.

nikademous

Technical User
Sep 9, 2018
41
US
I found a module to resize my image frame and I keep getting a Overflow error when it opens and it takes me to:

error_6_infazn.jpg


Any ideas on how to fix?

Code:
Option Compare Database
Option Explicit


'This function will resize and center an image frame based on the
'dimensions of any image.
Public Function fResizeImageFrame(ctl As Control)


    Dim fraLeft As Integer
    Dim fraTop As Integer
    Dim fraHgt As Integer
    Dim fraWdt As Integer
    Dim picHgt As Integer
    Dim picWdt As Integer
    Dim pct As Double
    Dim fra As Double
    Dim pic As Double
    
    
    
    'get dimensions of the image frame
    fraLeft = ctl.Left
    fraTop = ctl.Top
    fraHgt = ctl.Height
    fraWdt = ctl.Width
    
    'get dimensions of the image in the frame
    picHgt = ctl.ImageHeight
    picWdt = ctl.ImageWidth

    'get a percent value for the frame and image
    'which is based on the dimensions of each
    fra = fraWdt / fraHgt
    pic = picWdt / picHgt

'pics dimensions smaller than entire frame
    If fraHgt > picHgt And fraWdt > picWdt Then
        'resize frame to fit pic
        ctl.Height = picHgt
        ctl.Width = picWdt
        'center frame
        ctl.Left = fraLeft + ((fraWdt - picWdt) / 2)
        ctl.Top = fraTop + ((fraHgt - picHgt) / 2)
'pics dimensions taller than frame dimensions
    ElseIf pic < fra Then
        'determine percentage the pic is being reduced
        pct = fraHgt / picHgt
        'calculate the new pic width
        picWdt = picWdt * pct
        'resize frame to fit pic
        ctl.Width = fraWdt - (fraWdt - picWdt)
        'center frame
        ctl.Left = fraLeft + ((fraWdt - picWdt) / 2)
'pics dimensions wider than frame dimensions
    ElseIf pic > fra Then
        'determine percentage the pic is being reduced
        pct = fraWdt / picWdt
        'calculate the new pic height
        picHgt = picHgt * pct
        'resize frame to fit pic
        ctl.Height = fraHgt - (fraHgt - picHgt)
        'center frame
        ctl.Top = fraTop + ((fraHgt - picHgt) / 2)
    End If


End Function
 
I would try change some integers to Long. The maximum value for an integer is 32767. Have you determined the values by setting a breakpoint or using debug.print?

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
The problem is that, for whatever reason, both picWdt and picHgt are zero
 
Good catch Strongm. I typically check a divisor for 0 before performing a division.

The size and resolution of current monitors can also cause errors if you have code that uses a variable to set the form or control width larger than what an integer can support.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
For the specific overflow shown here (where pic seems to be equal to -1.#IND) both numerator and denominator have to be 0

The reason I said "for some reason" was to try and encourage the OP to investigate - but I'm having a quiet day, so ... this would typically happen in this specific example if thhere was no picture currently assigned to the Image control (and thus both ImageHeight and ImageWidth would be 0)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top