CInt
 
Converts numeric or string expression to an Integer

Syntax

Declare Function CInt ( ByVal expression As datatype ) As Integer

Type typename
End Type

Usage

result = CInt( numeric expression )
result = CInt( string expression )
result = CInt( user defined type )

Parameters

expression
a numeric, string, or pointer expression to cast to a Integer value
datatype
any numeric, string, or pointer data type
typename
a user defined type

Return Value

An Integer value.

Description

The CInt function rounds off the decimal part of numeric expression and returns a 32-bit Integer. The function does not check for an overflow, so be sure not to pass a value which is less than -2 147 483 648 or larger than 2 147 483 647. The name is derived from 'Convert to INTeger'.

If the argument is a string expression, it is converted to numeric by using ValInt.

Example

' Using the CINT function to convert a numeric value

'Create an INTEGER variable
Dim numeric_value As Integer

'Convert a numeric value
numeric_value = CInt(-300.23)

'Print the result, should return -300
Print numeric_value
Sleep


Dialect Differences

  • In the -lang qb dialect, CInt will return a 16-bit integer, like in QB.

Differences from QB

  • The string argument was not allowed in QB

See also