Visual Basic Language Reference  

CType Function

Returns the result of explicitly converting an expression to a specified data type, object, structure, class, or interface.

CType(expression, typename)

Parts

expression
Any valid expression. If the value of expression is outside the range allowed by typename, an error occurs.
typename
Any expression that is legal within an As clause in a Dim statement, that is, the name of any data type, object, structure, class, or interface.

Remarks

CType is compiled inline, meaning the conversion code is part of the code that evaluates the expression. Execution is faster because there is no call to a procedure to accomplish the conversion.

Example

This example uses the CType function to convert an expression to the specified data type.

Dim MyNumber As Long
Dim MyNewType As Single
MyNumber = 1000
MyNewType = CType(MyNumber,Single)   ' MyNewType is set to 1000.0.

See Also

Type Conversion Functions