如何在VB中定义64位常量?

发布于 2024-07-13 00:10:08 字数 344 浏览 6 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小帐篷 2024-07-20 00:10:08

除了每年略多于 365 天(您需要添加 97 个闰日)这一事实之外,相乘以组成常量的每个值都是整数文字,因此在将它们分配给 UInt64 之前,它是全部在整数空间中完成。 尝试这个:

Friend Const xxx As UInt64 = 400UL * 365UL * 24UL * 60UL * 60UL

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:

Friend Const xxx As UInt64 = 400UL * 365UL * 24UL * 60UL * 60UL
歌枕肩 2024-07-20 00:10:08

在常量末尾放置一个散列,并将其声明为“双精度”...

我用我的位掩码字段执行此操作:

Public Const EDIT_TRANSACTION              As Double = 1073741824
Public Const EDIT_DWRDELIVERY              As Double = 2147483648#
Public Const ENTER_DWRORDER                As Double = 4294967296#
Public Const DELETE_DWRORDER               As Double = 8589934592#
Public Const DELETE_TRANSACTION            As Double = 17179869184#
Public Const DELETE_WATERORDER             As Double = 34359738368#
Public Const ENTER_METERREADING            As Double = 68719476736#

** 编辑 **

我想我对此进行了标记,因为这是我编写的旧代码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:

Public Const EDIT_TRANSACTION              As Double = 1073741824
Public Const EDIT_DWRDELIVERY              As Double = 2147483648#
Public Const ENTER_DWRORDER                As Double = 4294967296#
Public Const DELETE_DWRORDER               As Double = 8589934592#
Public Const DELETE_TRANSACTION            As Double = 17179869184#
Public Const DELETE_WATERORDER             As Double = 34359738368#
Public Const ENTER_METERREADING            As Double = 68719476736#

** 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. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文