CLng
Converts numeric or string expression to `Long` having the same size as `SizeOf(Any Ptr)`
Syntax
`
Declare Function CLng ( ByVal expression As datatype ) As Long
Type typename
Declare Operator Cast ( ) As Long
End Type
`
Usage
`
result = CLng( numeric expression )
result = CLng( string expression )
result = CLng( user defined type )
`
Parameters
`expression`
a numeric, string, or pointer expression to cast to a `Long` value
`datatype`
any numeric, string, or pointer data type
`typename`
a user defined type
Return Value
A `Long` value.
Description
The `CLng` function rounds off the decimal part and returns a 32 bit `Integer` or 64 bit `LongInt` value. The function does not check for an overflow. The name can be explained as 'Convert to LoNG'.
If the argument is a string expression, it is converted to numeric by using `ValInt` or `ValLng`.
`Long` has the same size as `SizeOf(Any Ptr)`.
Example
`
' Using the CLNG function to convert a numeric value
'Create an LONG variable
Dim numeric_value As Long
'Convert a numeric value
numeric_value = CLng(-300.23)
'Print the result, should return -300
Print numeric_value
Sleep
`
Differences from QB

- The string argument was not allowed in QB
- LONG is always 32 bit in QB

See also

- `CByte`
- `CUByte`
- `CShort`
- `CUShort`
- `CInt`
- `CUInt`
- `CULng`
- `CLngInt`
- `CULngInt`
- `CSng`
- `CDbl`