CLngLng
Coerces an expression to a LongLong.
Syntax: CLngLng( expression )
- expression
- required Any valid string or numeric expression in the range
-9,223,372,036,854,775,808to9,223,372,036,854,775,807. Fractions are rounded.
The return type is LongLong.
When the fractional part is exactly 0.5, CLngLng always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2. CLngLng differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number.
Note
Conversion functions must be used to explicitly assign LongLong to smaller integral types. Implicit conversions of LongLong to smaller integrals are not allowed.
Note
In VBA, LongLong (and therefore CLngLng) is restricted to 64-bit hosts. twinBASIC supports LongLong in both 32-bit and 64-bit modes — see Data Types.
Warning BETA 1034
The constant 2^63, one past the largest LongLong, converts to -9223372036854775808 with no error: CLngLng(2 ^ 63) and CLngLng(9223372036854775808#) do, and so does CLngLng(9223372036854775807), because a whole-number literal without the ^ suffix is a Double that rounds to 2^63. A Double variable holding 2^63 raises error 6, as the table below says. Write the largest value as 9223372036854775807^. 64-bit VBA raises error 6 for each of these constants.
Common Errors
| Error | When |
|---|---|
6 (&H6), Overflow | expression rounds to a number less than -9,223,372,036,854,775,808 or greater than 9,223,372,036,854,775,807 |
13 (&HD), Type mismatch | expression is a string that does not hold a number (a zero-length string included) |
94 (&H5E), Invalid use of Null | expression is Null |
Example
This example uses the CLngLng function to convert an expression to a LongLong.
Dim someValue As Variant
someValue = 9223372036854775807^
Dim longLongValue As LongLong
longLongValue = CLngLng(someValue)
MsgBox "The LongLong representation is: " & longLongValue