You work with numeric literals that are not variants. They are interpreted by the compiler as the smallest type needed to hold a literal value, although Byte values โโwill by default be of type Integer .
Debug.Print TypeName(1132747441) 'Long Debug.Print TypeName(1788441323) 'Long
As @ComIntern points out, you assign the result of 2 longs in the expression, the expression overflows before it is assigned to Variant v4
As @dazedandconfused noted, you can force literal values โโto a more appropriate type, and the expression will be evaluated, and a variant can be assigned.
To get the behavior that Microsoft documents for the Variant type, you need to force use literals for the version before using them in the expression. Both options will contain Long s, but you will get automatic retyping, which the documentation confirms.
Sub Test() Dim v1, v2, v3, v4 Debug.Print TypeName(1132747441) 'Long Debug.Print TypeName(1788441323) 'Long Dim v5, v6 v5 = 1132747441 v6 = 1788441323 Debug.Print TypeName(v5) 'Long Debug.Print TypeName(v6) 'Long v4 = v5 + v6 'OKAY Debug.Print TypeName(v4) 'Double v4 = 0 Debug.Print TypeName(v4) 'Integer v4 = CVar(1132747441) + CVar(1788441323) ' OKAY Debug.Print TypeName(v4) 'Double v1 = 569847501 + 54678 ' OKAY v2 = 7784687414
source share