VB CInt Function: Convert to Integer
In VB, the CInt function is used to convert an expression into an integer type. It rounds the expression to the nearest integer value. If the expression cannot be converted to an integer, a runtime error will occur. An example is shown below:
Dim myInt As Integer
myInt = CInt(3.14) ' myInt 等于 3
myInt = CInt(5.9) ' myInt 等于 6
myInt = CInt("10") ' myInt 等于 10
Note: When using the CInt function, make sure that the expression can be converted to an integer, or else a runtime error will occur. If you need to convert to an integer but are unsure if it will succeed, you can use the Integer.TryParse method for a safe conversion.