views:

475

answers:

2

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

+4  A: 

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
Joel Coehoorn
I borrowed from Bill on this one: I just had L and then saw his UI post and had to check to make sure that the long syntax worked the same before updating my answer.
Joel Coehoorn
A: 

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

LarryF
Since this works it's not fair to vote it down..+1
jyzuz