Results 1 to 19 of 19

Thread: [RESOLVED] runtime error overflow

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2016
    Posts
    11

    Resolved [RESOLVED] runtime error overflow

    Trying to divide these 2 figs and get the error. Pretty sure it has something to do with Dim'ing the varaibles v1 and v2

    Private Function diff_Calc(ByRef r As clsRecord, ByVal detailRecordNum As Integer) As Variant

    Dim v1 As Long
    Dim v2 As Long

    v1 = Val(F4_Calc(r, detailRecordNum))
    v2 = Val(Lp_Calc(r, detailRecordNum))

    diff_Calc = FormatNumber(v2 / v1, 1)

    End Function

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,482

    Re: runtime error overflow

    post back the results from your Immediate Window (Ctrl+G), after you add these lines after your DIM statement:
    Code:
    Debug.Print F4_Calc(r, detailRecordNum); Lp_Calc(r, detailRecordNum)
    If those statements produce an error, then the error may be occurring in those subroutines/functions.

    Also, do those F4_Calc & Lp_Calc modify the passed detailRecordNum parameter at all?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2016
    Posts
    11

    Re: runtime error overflow

    No errors from F4 OR Lp. They are calculated values. They display in the output.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,482

    Re: runtime error overflow

    Ok, but wanted to see those values when you get your error. That could help us explain to you why the error is occurring.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2016
    Posts
    11

    Re: runtime error overflow

    the results from the Debug.Print F4_Calc(r, detailRecordNum); Lp_Calc(r, detailRecordNum)
    Attached Files Attached Files

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,482

    Re: runtime error overflow

    What variable type do your F4 & lp functions return?

    In your results file, jump to the bottom of the list. There are 2 line where only one value printed out. Look at the last entry and 8 lines from the last entry. I'm guessing you get an error with those entries?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,123

    Re: runtime error overflow

    I suspect that v1 is 0 at some point, and you don't check to make sure v1 is not 0 before doing your (v2 / v1)
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,482

    Re: runtime error overflow

    Quote Originally Posted by passel View Post
    I suspect that v1 is 0 at some point, and you don't check to make sure v1 is not 0 before doing your (v2 / v1)
    Was thinking that also at first, but that would be a different error: division by zero
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,123

    Re: runtime error overflow

    I wondered it that were the case. Didn't test it. So, some integer type overflow likely somewhere in the chain. Carry on.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  10. #10
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    6,482

    Re: runtime error overflow

    I suspect we're getting inaccurate information. Basically, the way I read the OP (and the thread title), is that the following line is generating an overflow error:

    Code:
    
    diff_Calc = FormatNumber(v2 / v1, 1)
    
    I thought about it, and also played around with it, and I just don't see how that's possible, especially with v1 and v2 being Long type.

    Sure, it's easy to get a Divide-By-Zero, but an Overflow? If it were multiplication, an overflow would be easy, but not with division.

    Sure, the results are a floating-point (or, more specifically, a Double). But a Double can handle anything that Long division can throw at it.

    Code:
    
    Debug.Print TypeName(1&/2&)  ' Reports "Double".
    
    IMHO, we're not being told the correct code line that the error is reporting on.

    Maybe I'm getting hung up where jpatierno says "Trying to divide these 2 figs". If the error is occurring down in either the F4_Calc function or the Lp_Calc function, then that's an entirely different story.

    Also, jpatierno, you say that "Pretty sure it has something to do with Dim'ing the varaibles (sic) v1 and v2". I just really don't see how that's the case. Dim (declaration) statements (for a Long) are doing nothing more than setting up a four-byte area, creating pointers to those areas, and also letting any VB6 operations know that those four-bytes are always to be treated as a 2's compliment Longs. Not really much more to it.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  11. #11

    Thread Starter
    New Member
    Join Date
    Dec 2016
    Posts
    11

    Re: runtime error overflow

    I've tried a bunch of different options with no success so here's the whole program with the data file that it runs
    Attached Files Attached Files

  12. #12
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,482

    Re: runtime error overflow

    Didn't expect that. When you get the error, both v1 and v2 are zero. 0 divided by 0 gives you that error.

    You are going to need to step through some of your code and determine where in your f4/lp routines you are returning a value of zero. And if zeroes are valid, then you will want to test to ensure v1 <> 0 or v2 <> 0. If so, either your data is bad, your calculations are bad, or the result would be zero anyway.

    Look at your various "... = gFieldMapping.GetFieldValue(...)" methods. If the returned value is Empty, then you will be returning zero. In the case where the error occurred, these lines returned Empty:
    Code:
    result = gFieldMapping.GetFieldValue(r, "4f fig " & detailRecordNum)
    
    Lp_Calc = gFieldMapping.GetFieldValue(r, "lp " & detailRecordNum)
    Last edited by LaVolpe; Aug 6th, 2020 at 02:00 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  13. #13
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    6,482

    Re: runtime error overflow

    Ahhh, I played around with it and never thought to try 0&/0&. Apparently, that's the answer.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  14. #14

    Thread Starter
    New Member
    Join Date
    Dec 2016
    Posts
    11

    Re: runtime error overflow

    there are occasions where either F4 or Lp could be zero. Not on error though. So what code can over come this problem

  15. #15
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,482

    Re: runtime error overflow

    Quote Originally Posted by jpatierno View Post
    there are occasions where either F4 or Lp could be zero. Not on error though. So what code can over come this problem
    simple really
    Code:
    Private Function diff_Calc(ByRef r As clsRecord, ByVal detailRecordNum As Integer) As Variant
    
    Dim v1 As Long
    Dim v2 As Long
    
    v1 = Val(F4_Calc(r, detailRecordNum))
    If v1 = 0 Then
         diff_Calc = 0
    Else
        v2 = Val(Lp_Calc(r, detailRecordNum))
        If v2 = 0 Then
             diff_Calc = 0
        Else
            diff_Calc = FormatNumber(v2 / v1, 1)
        End If
    End If
    
    End Function
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  16. #16

    Thread Starter
    New Member
    Join Date
    Dec 2016
    Posts
    11

    Re: runtime error overflow

    Yes. That did it. Thank you very much

  17. #17

    Thread Starter
    New Member
    Join Date
    Dec 2016
    Posts
    11

    Re: runtime error overflow

    How do you show the thread was resolved?

  18. #18
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,482

    Re: runtime error overflow

    "Thread Tools" menu near top of your first posting
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  19. #19
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,288

    Re: runtime error overflow

    Interesting, the overflow error message is a bit of a red herring it seems. I would not expect to see that error message when dealing with 0s. I would expect to see division by 0 but not the first time I have saw miss leading error messages.

    I once had an error in a large program written by others that I had to track down. The error was "Statement to complex to process" The line that threw the error was RS.MoveLast or maybe it was RS.MoveFirst. [been a long time now] Anyway that had me scratching my head for a little while. Turned out the problem was that whoever designed the db used a text field for the qty and allowed it to be null. The query did some operation related to this field and the nulls caused a problem. Oddly the open rs worked without throwing an error but the move method took down the system and of course whoever coded it did not have an error trap in there so it crashed to the desktop. The odd error message had me looking in the wrong place for a bit but I managed to locate the issue and correct it Initially just by running an update query and setting all null qty to 0, Later I modified the db to use a numeric field and 0 default.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width