Syntax |
CInt(expression) |
Description |
Converts expression to an Integer. |
Comments |
This function accepts any expression convertible to an Integer, including strings. A runtime error is generated if expression is Null. Empty is treated as 0. The passed numeric expression must be within the valid range for integers: –32768 <= expression <= 32767 A runtime error results if the passed expression is not within the above range. When passed a numeric expression, this function has the same effect as assigning a numeric expression to an Integer. Note that integer variables are rounded before conversion. When used with variants, this function guarantees that the expression is converted to an Integer variant (VarType 2). |
Example |
This example demonstrates the various results of integer manipulation with CInt. Sub Main() '(1) Assigns i# to 100.55 and displays its integer representation (101). I# = 100.55 MsgBox "The value of CInt(i) = " & CInt(i#) '(2) Sets j# to 100.22 and displays the CInt representation (100). j# = 100.22 MsgBox "The value of CInt(j) = " & CInt(j#) '(3) Assigns k% (integer) to the CInt sum of j# and k% and displays k% '(201). k% = CInt(i# + j#) MsgBox "The integer sum of 100.55 and 100.22 is: " & k% '(4) Reassigns i# to 50.35 and recalculates k%, then displays the result '(note rounding). i# = 50.35 k% = CInt(i# + j#) MsgBox "The integer sum of 50.35 and 100.22 is: " & k% End Sub |
See Also |
CCur (function); CBool (function); CDate, CVDate (functions); CDbl (function); CLng (function); CSng (function); CStr (function); CVar (function); CVErr (function); Integer (data type). |
C |