Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a constant for max value for integer type?

Tags:

vba

ms-access

I'm searching for a constant like MAXINT in c, for VBA code. I found references only in other languages, and cannot find one for VBA.

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

like image 767
MJH Avatar asked Jun 15 '16 13:06

MJH


1 Answers

VBA does not provide a MAXINT constant. But you can derive that value easily:

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

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

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

Then MAXINT would be available for the rest of your VBA code in that application.

And for Long Integer, the maximum value is ...

MAXLONG = (2 ^ 31) -1
Debug.Print MAXLONG
 2147483647 
like image 116
HansUp Avatar answered Sep 28 '22 02:09

HansUp