Results 1 to 4 of 4

Thread: [RESOLVED] Overflow error '6'

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2016
    Posts
    52

    Resolved [RESOLVED] Overflow error '6'

    Hey all,

    A sub I'm working on refuses to work, due to an overflow error in the following code:

    Code:
        Dim i As Integer, , j As Integer, OldPatchY As Integer, NewPatchY As Integer, OldPatchX As Integer, _
        NewPatchX As Integer, XDifference As Integer, YDifference As Integer, Mini As Integer, _
        Max As Integer, NewPlantX As Integer, NewPlantY As Integer, 
        
        Mini = 99999999
        Max = 0
    When stepping through, the moment I reach mini = 9999999, I get an overflow error. I can't really see why though; it's within the bounds of an integer, I've tried reducing the number to 1000, changing the name of the variable, and where it is declared. Later on in the code, I will simply be using the variable to find the minimum number in an array of integers using an if loop.

    I hope I'm not just ignoring something obvious!

    Cheers.

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,905

    Re: [RESOLVED] Overflow error '6'

    An integer can not hold a value of 9999999, instead declare your variables as Long
    Check the min and the max values for integers in the help (press F1 with the cursor on Integer)
    Integer variables are stored as 16-bit (2-byte) numbers ranging in value from -32,768 to 32,767.

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2016
    Posts
    52

    Re: [RESOLVED] Overflow error '6'

    Quote Originally Posted by Arnoutdv View Post
    An integer can not hold a value of 9999999, instead declare your variables as Long
    Check the min and the max values for integers in the help (press F1 with the cursor on Integer)
    I've seen this quoted many times, but on the MSDN 'Integer Data Type' webpage it states:

    'Holds signed 32-bit (4-byte) integers that range in value from -2,147,483,648 through 2,147,483,647.'

    Any chance you know the reason?

    Cheers for your help though!

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,905

    Re: [RESOLVED] Overflow error '6'

    I bet you are checking MSDN for VB.Net and not VBA or VB6.

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