在 VBA 中计算常量时发生溢出
此声明会导致 VBA 溢出:
Const OVERFLOWS As Long = 10 * 60 * 60
而直接设置值就可以了:
Const COMPILES_OK As Long = 36000
How do you suggest VBA to treatliteral integers as longs?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
http://support.microsoft.com/kb/191713 是该类型的一个很好的总结VBA / VB4-6 中可用的声明字符。
http://support.microsoft.com/kb/191713 is a nice summary of the type declaration characters available in VBA / VB4-6.
对于那些发现 & 符号有点深奥,另一种方法是使用 CLNG 函数,它将数字转换为 long,
然后您可以对 Single 常量执行类似的操作
For those who find the & symbol a bit esoteric, an alternative is to use the CLNG function which converts a number to long
you could then do a similar thing for a Single constant
类型字符也可以附加到文字上:Const OVERFLOWS As Long = (10& * 60 * 60)
(实际上,一个就足够了,因为 VBA 引擎计算表达式的方式)。
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).
将
long
后缀&
添加到至少一个数字:请注意,使用
CLNG
函数将值转换为long 不起作用,因为 VBA 不允许将函数的返回值分配给常量。
Add the
long
suffix&
to at least one number:Note that using the
CLNG
function to convert the values tolong
will not work, because VBA does not allow assigning the return value of a function to a constant.