Results 1 to 25 of 25

Thread: Very strange Overflow error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    182

    Very strange Overflow error

    So this is very strange or can anyone explain to me why I get an Error 6:Overflow at line 100 in this code?
    Code:
    Public Function CalculateT(ByVal IsGregorianCal As Long) As Double
        'On Error Resume Next
            '<EhHeader>
            On Error GoTo CalculateT_Err
            '</EhHeader>
    100 P = 12.3 
    102 ta = 21012.5 
    104 T = 0.575304928131417
    106 T = T + 1.01603937491912E-08 
    108 T2 = T * T
    110 T3 = T2 * T
    112 T4 = T3 * T
    114 CalculateT = T * 36525
            '<EhFooter>
            Exit Function
    
    CalculateT_Err:
            With Err
                MsgBox .Description & vbNewLine & _
                   "in CalculateT " & _
                   "at line " & Erl & vbNewLine & _
                   "The program may not be able to continue.", _
                   vbExclamation + vbOKOnly, .Source & str$(.Number)
            End With
    
            '</EhFooter>
    End Function
    All variables in the function is declared as Public elsewhere.
    The litteral values are actually either return values from a function or the calculated result of an expression. I changed this from the original to make it all clearer. It doesn't change anything though.

    The really strange thing is that e.g. I can swap the 2 first code lines, and the error will still be triggered on the first line. Indeed, I can comment out all lines except the first and it still gives an Overflow error, also if I wrap it in CDbl(12.3).

    I thought it may had to do with the bas file being >64k, which it in fact was (73k) but splitting it up the code in to 2 files both < 64k doesn't make any difference.

    There are a few more things to it worth mentioning as well. If I change the error trap code to 'On Error Resume Next' code runs fine, variables are filled with assigned values, in IDE. However, running the compiled exe the first variable always are assigned exactly 0 or probably isn't assigned at all, just staying at 0. Now, if I repeat the code with the same line a second time like
    P = 12.3
    P = 12.3

    and compile (with 'On Error Resume Next') it runs fine and vars are all assigned values.

    Program code is fairly large, about 65 000 lines of code, can that be it that I have run into some kind of (hidden?) limitations?

    If anyone has some input on this I'm grateful, thanks.
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Very strange Overflow error

    All variables in the function is declared as Public elsewhere.
    so what is P dimensioned as?
    do you have option explicit at the top of module?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Very strange Overflow error

    There is no limit in overall program code size.
    There once was a limit of 64k on a module, not sure if that limit still exists or not.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    182

    Re: Very strange Overflow error

    Thanks for replying.
    Quote Originally Posted by westconn1 View Post
    so what is P dimensioned as?
    Public P As Double

    Quote Originally Posted by westconn1 View Post
    do you have option explicit at the top of module?
    Yes, of course. All variables are declared/dimensioned, no Variants.

    I know what an Overflow error is and what causes it. This one just doesn't seem to follow the rules, or at least it appears so. There is probably something else at play here, but what?

    I can basically place any one liner in that procedure that assigns to a Public Double variable, strip out all other code, and it Overflows. Very strange.
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Very strange Overflow error

    Very strange indeed. I have never saw anything like this. I would expect that something else is going on somewhere and causing the problem.

    What happens if you put that function in a new project, dim the required vars and run it?

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    182

    Re: Very strange Overflow error

    Here are some statistics about the project, which is pretty big as you can see. I said about 65 000 lines above, as that's what I thought it was but after a closer look that's something of an understatement.
    Code:
    Lines
    ----------
    Code Lines: 74,388 (69.55%)
    Comment Lines: 10,441 (9.76%)
    Blank Lines: 22,131 (20.69%)
    TOTAL LINES: 106 960
    
    Members
    -----
    Public Events: 2
    Properties: 162
    Methods: 3,478
    TOTAL MEMBERS: 3,642
    
    Components
    -------
    Modules: 29
    Classes: 8
    Forms: 63
    TOTAL COMPONENTS: 100
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    182

    Re: Very strange Overflow error

    Quote Originally Posted by DataMiser View Post
    Very strange indeed. I have never saw anything like this. I would expect that something else is going on somewhere and causing the problem.

    What happens if you put that function in a new project, dim the required vars and run it?
    Yes, just did that and surprise surprise, or not really, it works w/o problem. Of course it does as there really isn't anything wrong with the function as far as I can see. A sucker really.
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Very strange Overflow error

    Sounds like may be hard to find, could be in a different module, class or form. Are you using any 3rd party controls? API calls, DLLS, and such?

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    182

    Re: Very strange Overflow error

    Quote Originally Posted by DataMiser View Post
    Sounds like may be hard to find, could be in a different module, class or form. Are you using any 3rd party controls? API calls, DLLS, and such?
    I do, UniSuitePro unicode controls (definitely a candidate), Some API's, another dll called "Time2Win.dll" which may also be a candidate as the programmer seem to have disappeared, Olaf's vbRichClient5.dll, some PowerBasic and ActiveX.dll|ocx I have written myself so yes you are right, like looking for a byte in a digital haystack!

    I will leave the topic as unsolved for now, in case some really smart guy with a bright idea is passing by ;=) and for now at least have to satisfy with the workaround of duplicating the first code line which together with "On Error Resume Next" makes the code work as intended. The problem is obviously still there though and may pop up elsewhere at a later stage.
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  10. #10
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Very strange Overflow error

    Sometimes the IDE (less when running in natively compiled code) *does* strange things,
    especially when the module- and code-volume is really large.

    But maybe there's another global 'P'-Variable somewhere in a different module, or another
    symbol which slipped by the compiler, due to the sheer code-volume it has to handle.
    (in this case an explicit write-up of modMyModuleInQuestion.P might help the issue)...

    In larger projects I try to avoid too many global Variables which are "simple Standard-Types"
    (instead try to encapsulate them in Classes - and then make only these "Singleton-Classes" global).

    If there's certain Modules which hosts a lot of them, then it often helps to treat these modules more
    like "Static Classes" (without a need to be instantiated, but then offering Methods and Public Properties
    instead of global Vars directly).
    The formerly global Vars can then be made Private, visible only within the *.bas-Module in question -
    and all relevant functions (as e.g. your DateConversion- and Calendar-stuff) are written as
    Public Methods which make use of those internal Private Vars - just like in a real Class-encapsulation).

    Maybe changing that in a few places (thus reducing the amount of "the global bunch" the compiler
    needs to keep notes about) will help in your case.

    And since your project is quite large - and you're shipping external dependencies anyways -
    why not move stuff which can be considered "stable and unchanging code-wise" into dedicated
    Dll-encapsulations, where you switch Binary-Compatibility On.

    That will result in less code in the Main-Project, eases the burden of the compiler whilst working
    in it (faster startup-times - faster responding intellisense again - etc.).


    Olaf

  11. #11
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Very strange Overflow error

    What is returned if you add this line before line 100?

    Debug.Print vartype(P)

  12. #12
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Very strange Overflow error

    Which line is line 100?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  13. #13
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Very strange Overflow error

    Quote Originally Posted by Nightwalker83 View Post
    Which line is line 100?
    ummm the code has line numbers in it so it would be this one

    Code:
    100 P = 12.3

  14. #14
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Very strange Overflow error

    Without the full source of a case that reproduces the problem we're just shooting in the dark.

    I don't doubt that it is happening, but I do doubt it is a failure in VB6. Far more likely? A progamming bug, a case where the actual code doesn't match your mental model of the code. In particular a difference in data scope, and thus data type... i.e. the "wrong P" here. This was suggested in post #10 above too.

    Open the project in the IDE, right click on the failing line's "P" variable, choose "Definition" from the context menu.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    182

    Re: Very strange Overflow error

    @Schmidt: Olaf, you give many good advices as usual and indeed most of them have already been done or are ongoing. This project has a history of over 30 years originally taking off in 1982 on a Video-Genie, a Tandy TRS80 clone and the Commodore PET, by others than me. I first got involved in the early -90's when it was at DOS level coded in QB2.5 (if I remember correct) and eventually fully took it over about 10 years ago bringing it from VB3 to VB6. Since then I have rewritten lots of it, added, got lost a few times, but well there are still a decent amount of old code that has a potential to create problems, while I may have introduced some as well.
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    182

    Re: Very strange Overflow error

    Quote Originally Posted by MarkT View Post
    What is returned if you add this line before line 100?

    Debug.Print vartype(P)
    Interesting, it prints 5 but most of all - it doesn't generate any error any longer!
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    182

    Re: Very strange Overflow error

    Quote Originally Posted by dilettante View Post
    Without the full source of a case that reproduces the problem we're just shooting in the dark.
    Yes you are right. Unfortunately that's not really feasible, at least not now, as this is a small part of a bigegr whole and I would have to spend a lot of time separating it all out. I may eventually do that to get to the core, but for now I am satisfied with a temporary workaround. Actually, I will rewrite this part soon to "classify" it which may or may not solve it, time will show.

    Quote Originally Posted by dilettante View Post
    I don't doubt that it is happening, but I do doubt it is a failure in VB6. Far more likely? A progamming bug, a case where the actual code doesn't match your mental model of the code. In particular a difference in data scope, and thus data type... i.e. the "wrong P" here. This was suggested in post #10 above too.

    Open the project in the IDE, right click on the failing line's "P" variable, choose "Definition" from the context menu.
    Well this isn't my first project, well in a sense it is, but I have been with VB6 basically since the beginning (which you can't know of course), so while it may still be something with the code it's not a simple mistake as that. Project still has a decent amount of global variables, which I'm constantly hunt down on, but if it's the "wrong P" here as you suggest it's certainly VB6 that gets it wrong, not the code declarations. By the way, it doesn't matter which variable I try to assign to as the first line, it still triggers this Overflow error.

    At this point it's probably hard to get any further, unless the result from the suggestion by user MarkT fire up some VB6 guru light-bulbs. Otherwise, if no one has shown any further interest in this topic within 24h or so I will mark it as Solved, to give other more urgent topics more attention.
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  18. #18
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Very strange Overflow error

    The VarType 5 == vbDouble - so that's not the problem...

    Hmm, a thing which runs basically in the same category of "no clue where this error comes from"
    is, when you use one of these "Not Not " based "Is Array initialized" checks - then in later
    routines unexpected errors were showing up.

    Here's a small Demo to reproduce what I mean:
    http://www.vbforums.com/showthread.p...=1#post4532243

    So, if by any chance you work with some check like that in a few places, then it could be one reason.

    Olaf

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    182

    Re: Very strange Overflow error

    Quote Originally Posted by Schmidt View Post
    The VarType 5 == vbDouble - so that's not the problem...

    Hmm, a thing which runs basically in the same category of "no clue where this error comes from"
    is, when you use one of these "Not Not " based "Is Array initialized" checks - then in later
    routines unexpected errors were showing up.

    Here's a small Demo to reproduce what I mean:
    http://www.vbforums.com/showthread.p...=1#post4532243

    So, if by any chance you work with some check like that in a few places, then it could be one reason.

    Olaf
    No such checks. The arrays involved in the surrounding code are all statically dimensioned, although some are multi dimensioned. I believe we can guess until we are blue without finding out what it really is, so I will satisfy with my workaround for now, but keep an eye on it as I rewrite code to see if I can locate the defending part, then report back here and "close" as Solved. Thanks for your input guys.
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  20. #20
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Very strange Overflow error

    Probably a silly question, but have you patched VB6 fully up to Service Pack 6?

    The pre-SP6 days are so far behind now that keeping bugs from that long ago in mind is getting difficult.

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    182

    Re: Very strange Overflow error

    Quote Originally Posted by dilettante View Post
    Probably a silly question, but have you patched VB6 fully up to Service Pack 6?

    The pre-SP6 days are so far behind now that keeping bugs from that long ago in mind is getting difficult.
    Yes, SP6 all the way.
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  22. #22
    Lively Member
    Join Date
    Oct 2013
    Posts
    124

    Re: Very strange Overflow error

    I've run into situations like this caused by not having an error handler in the module where the error actually occurs, but having one in the module before that. It appears that if there is no error handler where the error occurs VB backtracks to a module that does have an error handler. So, for development, I either put error handlers in all modules, or none.
    Last edited by Honduras 2811; Apr 12th, 2014 at 04:02 PM. Reason: Spelling error.
    AMD FX-4300, WinXPSP3, VB6SP6

  23. #23
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Very strange Overflow error

    Quote Originally Posted by DataMiser View Post
    ummm the code has line numbers in it so it would be this one

    Code:
    100 P = 12.3
    Didn't realize that!

    Quote Originally Posted by MarkT
    Debug.Print vartype(P)
    I have encountered other times that a variable fails to update without having the variable data being printed to the debug window. I wonder why it happens though?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  24. #24
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Very strange Overflow error

    I had an issue a few years ago with Embedded VB 3.0 where an If statement would fail for no apparent reason. I never did find the reason and ended up coding around it to get the project done. I never saw the issue in any other project and still no idea why it did what it did. Not related to this but maybe of interest.

    Basically I had a statement something to the effect of
    If X=0 then

    For whatever reason when debugging X would show =0 but the code after the If did not execute
    I ended up changing the statement to something like

    If Not(X<>0) then

    And it worked just fine

    Made no sense whatsoever but I had to move on.

  25. #25

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    182

    Re: Very strange Overflow error

    Quote Originally Posted by Honduras 2811 View Post
    I've run into situations like this caused by not having an error handler in the module where the error actually occurs, but having one in the module before that. It appears that if there is no error handler where the error occurs VB backtracks to a module that does have an error handler. So, for development, I either put error handlers in all modules, or none.
    That's not the case here, but thanks for your contribution to the discussion.
    Last edited by 7edm; Apr 13th, 2014 at 02:56 AM. Reason: spelling
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

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