Returns the result of explicitly converting an expression to a specified data type, object, structure, class, or interface.
- Any valid expression. If the value of expression is outside the range allowed by typename, an error occurs.
- 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.
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.
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.