Explicit Conversion
Is done using one of the data type conversion functions listed below.
This is more risky as there is a possibility that some data or significant figures can be lost.
Consider converting a single value to an Integer.
Since a single value takes up to 4 bytes and an Integer takes up to 2 bytes, some data will be lost.
Narrowing casts must be explicit.
All the conversion functions can automatically handle locale issues
That means that they will take international date/time and number regional settings into account.
Conversion Functions
CBOOL | Returns the expression converted to a boolean data type (Boolean). Converts any valid string or numeric expression to a boolean. |
CBYTE | Returns the expression converted to a byte data type (Byte). Converts numeric expressions 0-255 to Byte. Rounds fractional parts. |
CCUR | Returns the expression converted to a currency data type (Currency) |
CDATE | Returns the expression converted to a date data type (Date). Converts any valid date or time representations to the Date type. |
CDBL | Returns the expression converted to a double data type (Double), Converts any expression that can be evaluated as a number to a Double. assuming it is in the range of a Double. |
CDEC | Returns the expression converted to a decimal subtype (Variant). Converts any expression that can be evaluated as a number to a Decimal. |
CINT | Returns the expression converted to an integer data type (Integer). Converts any expression that can be evaluated as a number to an Integer. Rounds fractional parts. |
CLNG | Returns the expression converted to a long data type (Long). Converts any expression that can be evaluated as a number to a Decimal. |
CLNGLNG | Returns the expression converted to a long data type (64 bit only) (Long). Converts any expression that can be evaluated as a number to a Decimal. |
CLNGPTR | |
CSNG | Returns the expression converted to a single data type (Single). |
CSTR | Returns the expression converted to a string data type (String). |
CVAR | Returns the expression converted to a variant data type (Variant). |
CVDATE | Returns the expression converted to a date data type (Variant). |
CVERR | Returns the corresponding to a given error number (Variant). |
INT* | Returns the number rounded down to the nearest integer (Double). |
STR* | Returns the text string of a number (String). |
*These are only included for backwards compatibility and should not to used.
In VB.Net and VB 6.0 there are CCHAR, COBJ and CSHORT functions. These are not available in VBA.
If you have any problems with the Int() or Cint() type conversion functions then use the Str() function to return a string representation of the number first, before converting.
© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext