none
Compile Error - Overflow on Const declaration, and on Double value assignment RRS feed

  • Question

  • Symptom description: 

    Hei der,

    I have two overflow issues with VBA, see list below. Cannot quite understand why I am getting them, do I need to be more explicit when declaring? Could it be a lack-of-memory issue? 


    1. Run-time Error 6: Overflow
    This one happens when VBA is executing the following lines:
    Dim variableA As Double
    variableA = 15.62

    If declaring variableA = 0# before setting to 15.62, no oveflow appears.


    2. Compile Error Overflow 
    (warning dialog box pops up)This one happens when VBA is executing the following lines:
    Const origo = -2.456789


    Environment: Windows XP SP3, RAM 4Gb etc.
    Visual Basic 6.3


    • Edited by Jarlesh Tuesday, April 8, 2014 9:50 AM
    Tuesday, April 8, 2014 9:41 AM

All replies

  • There's nothing in what you've posted that should lead to an overflow error. In a new project do debug / compile with this

    Sub abc()
    Const origo = -2.456789
    Dim variableA As Double
    variableA = 15.62
    End Sub

    It would be better though to declare the constant like this

    Const origo As Double = -2.456789

    Tuesday, April 8, 2014 11:06 AM
    Moderator
  • Thanks for the reply, 

    the code compiles, and does run sometimes without Overflow.
    I am wondering if anything else might affect this Overflow? Other VBA code that executes when it should not etc.? Memory issues?
    Wondering if someone have seen something similar.

    Also, if declaring variableA = 0# before setting to 15.62, no oveflow appears.

    Mvh
    Jarle

    Wednesday, April 9, 2014 7:57 AM
  • Without seeing your project difficult to suggest but normally if a variable is declared as a Double it starts with a double 0, the same as your 0#. If the variable was a variant and at some stage had been assigned say 123, it's type would be Variant/Integer, then if you assign it 0# it will change to a variant/double. But that doesn't apply to you, unless there's more you haven't shown us.

    Another reason for overflows within intermediate calculations, eg

    Dim a As Long, b As Long
    Dim c As Double
    a = 1000
    b = 10000000
    c = a * b  ' overflow
    c = CDbl(a) * b ' works

    Wednesday, April 9, 2014 11:48 AM
    Moderator
  • Okay thanks, 

    no there really isn't anything I haven't shown you. The sub is basically just declaring the variables as shown, and then used in a calculation. I have one sub with Overflow on the lines variableA = 15.62 and another one on the line Const origo = -2.456789. 

    Thanks for replying, I will try to troubleshoot some more. 

    Thursday, April 10, 2014 8:38 AM