如何在VB中定义64位常量?
在 Visual Basic 中,
Friend Const xxx As UInt64 = 400 * 365 * 24 * 60 * 60 ''// Number of secs in 400 years
此操作失败并出现错误
constant expression not representable in type integer
The Problem is 400 * 365 * 24 * 60 * 60 is more than 2^32
我本以为通过将常量声明为 UInt64 可以将 64 位值分配给它
In Visual Basic
Friend Const xxx As UInt64 = 400 * 365 * 24 * 60 * 60 ''// Number of secs in 400 years
This fails with the error
constant expression not representable in type integer
The problem is 400 * 365 * 24 * 60 * 60 is larger than 2^32
I would have thought that by declaring the constant to be UInt64 that it would be OK to assign a 64 bit value to it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了每年略多于 365 天(您需要添加 97 个闰日)这一事实之外,相乘以组成常量的每个值都是整数文字,因此在将它们分配给 UInt64 之前,它是全部在整数空间中完成。 尝试这个:
Aside from the fact that there are slightly more than 365 days each year (you need to add 97 leap days), each of the values that are multiplied to make up your constant are integer literals, and therefore until you assign them to the UInt64 it's all done in integer space. Try this:
在常量末尾放置一个散列,并将其声明为“双精度”...
我用我的位掩码字段执行此操作:
** 编辑 **
我想我对此进行了标记,因为这是我编写的旧代码VB6,并不完全是你所要求的。 因此,如果阅读本文的人正在使用 VB6,并且必须将位掩码字段传递给 SQL 之类的东西,那么这对我来说非常有效。
否则,请继续投票否决我的答案。 :)
Put a hash at the end of the constant, and declare it as a 'double'...
I did this with my bitmask fields:
** EDIT **
I guess I got marked down on this because this was old code I wrote for VB6, and not exactly what you were asking for. So, if anyone reading this is using VB6, and have to pass Bitmask fields to something like SQL, this is what worked perfectly for me.
Otherwise, just keep voting my answer down. :)