문제

이 선언은 VBA에서 오버플로를 유발합니다.

Const OVERFLOWS As Long = 10 * 60 * 60

값을 직접 설정하는 것은 괜찮습니다.

Const COMPILES_OK As Long = 36000

문자 그대로의 정수를 오랫동안 취급하도록 VBA를 어떻게 설득합니까?

감사

도움이 되었습니까?

해결책

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.

다른 팁

http://support.microsoft.com/kb/191713 is a nice summary of the type declaration characters available in VBA / VB4-6.

For those who find the & symbol a bit esoteric, an alternative is to use the CLNG function which converts a number to long

Const OVERFLOWS As Long = CLNG(10) * 60 * 60

you could then do a similar thing for a Single constant

Const OVERFLOWS As Single = CSNG(10) * 60 * 60

The type character can also be appended to literals : Const OVERFLOWS As Long = (10& * 60 * 60) (one is suffucient actually because of the way the VBA engine evaluates the expression).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top