Home > Language Reference > Functions > Data Types

CInt Function

Conversion into a Integer type.

Syntax

CInt( Expression )

ParameterDescription
ExpressionExpression to convert into an Integer type.

Remarks

The CInt reserved keyword is syntactically equivalent to a function returning a Integer type, and can be used everywhere that a function is accepted.

Only Boolean, Date type expressions and object references cannot be converted into type Integer. All attempts to use this keyword on one of these expressions will cause a runtime error.

At runtime, when Expression is a string (or a Variant containing a string), it should not contain thousands separators and the decimal separator should be a decimal point. If necessary, you can use the DelocalizeNumber function to check it.

If the string contains a whole number, it is possible to prefix it with "&B", "&O" or "&H" in order to indicate that the number is expressed in binary, octal or hexadecimal respectively. The following example converts the hexadecimal value entered into a text box into a decimal value:

Private Sub Button1_Click()
  Dim k as Integer

  k = CInt( "&H" & Field1.Text )
  MsgBox CStr(k)
End Sub

When Expression is a decimal value, it is rounded towards zero, that is to say that the figures following the decimal place are removed. In all cases, a runtime error will occur if Expression cannot be converted into a numeric value in the range -32768..32767.

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0-
Windows CEWindows CE 3.0-