Results 1 to 7 of 7

Thread: variable overflow in VBA

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    variable overflow in VBA

    Hello

    I was wondering what happened to the execution of a program after a variable overflows. does the program continue right after the code which does the overflow or is the execution indeterminate.

    i have got this piece of code which seems to run of to the begining of the loop (where the offending piece of code was within the loop)

    also in vba is there any way to ifnd out if a variable has overflown by using a breakpoint.

  2. #2
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    Re: variable overflow in VBA

    What happens on a overflow depends on your error handling
    3 Examples, Normal, with error handling and the worst ignoring any errors
    Code:
    Sub test1()
    
    Dim I As Integer
    
    For I = 32760 To 32768
    
    Next
    
    End Sub
    
    Sub test2()
    
    Dim I As Integer
    
    On Error GoTo test2_Error
    
    For I = 32760 To 32768
    
    Next
    
       On Error GoTo 0
       Exit Sub
    
    test2_Error:
    
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure test2 of Module Module1"
    
    End Sub
    
    Sub test3()
    
    Dim I As Integer
    On Error Resume Next 'this will ignore the error and continue
    For I = 32760 To 32768
    
    Next
    
    End Sub
    Now with a nice errorhandler
    why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
    for every question you ask provide an answer on another thread.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: variable overflow in VBA

    thanks for the reply

    i guess without the error handler, the behaviour is indeterminate, correct?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: variable overflow in VBA

    If the variable overflows you will generate an error. Just trap for that error. Best thing to do i=s to dimension your variables with the proper type and size.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: variable overflow in VBA

    thanks for the reply robdog

    what kind of error will the variable overflow generate?

    how does one trap for that error?

    what is i=s?

  6. #6
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: variable overflow in VBA

    Well, create the overflow and see what the error number is. Then trap for that in your error handler (If err.Number = 5614 then... and no, I don't know what the correct error number is, 5614 is an example).
    i=s is probably a typo for is, as in "Best thing to do is..."
    Tengo mas preguntas que contestas

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: variable overflow in VBA

    thanks for the reply

    there were overflows within my program, but the program just seemed to go in a loop and did not give any errors

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