Is there a constant for the maximum value for an integer type?

I am looking for a constant, such as MAXINT in c, for VBA code. I found links only in other languages ​​and cannot find them for VBA.

If there is no such constant, then what is the maximum number an int in VBA can contain? I tried 2147483647 but got an overflow error.

+7
vba access-vba ms-access
source share
1 answer

VBA does not provide a MAXINT constant. But you can easily get this value:

 MAXINT = (2 ^ 15) -1 Debug.Print MAXINT 32767 

Or you can define it as a Public constant with this in the Declarations section of the standard module:

 Public Const MAXINT As Integer = (2 ^ 15) - 1 

Then MAXINT will be available for the rest of your VBA code in this application.

And for Long Integer maximum value ...

 MAXLONG = (2 ^ 31) -1 Debug.Print MAXLONG 2147483647 
+13
source share

All Articles