Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overflow when calculating a const in VBA

This declaration causes an overflow in VBA:

Const OVERFLOWS As Long = 10 * 60 * 60

whereas setting the value directly is fine:

Const COMPILES_OK As Long = 36000

How do you persuade VBA to treat literal integers as longs?

Thanks

like image 526
Jonathan Webb Avatar asked Nov 04 '08 11:11

Jonathan Webb


1 Answers

Add the long suffix & to at least one number:

Const OVERFLOWS As Long = 10& * 60 * 60

Note that using the CLNG function to convert the values to long will not work, because VBA does not allow assigning the return value of a function to a constant.

like image 163
xsl Avatar answered Sep 29 '22 13:09

xsl