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

CBOOLReturns the expression converted to a boolean data type (Boolean).
Converts any valid string or numeric expression to a boolean.
CBYTEReturns the expression converted to a byte data type (Byte).
Converts numeric expressions 0-255 to Byte.
Rounds fractional parts.
CCURReturns the expression converted to a currency data type (Currency)
CDATEReturns the expression converted to a date data type (Date).
Converts any valid date or time representations to the Date type.
CDBLReturns 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.
CDECReturns the expression converted to a decimal subtype (Variant).
Converts any expression that can be evaluated as a number to a Decimal.
CINTReturns 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.
CLNGReturns the expression converted to a long data type (Long).
Converts any expression that can be evaluated as a number to a Decimal.
CLNGLNGReturns 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 
CSNGReturns the expression converted to a single data type (Single).
CSTRReturns the expression converted to a string data type (String).
CVARReturns the expression converted to a variant data type (Variant).
CVDATEReturns the expression converted to a date data type (Variant).
CVERRReturns 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.



© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext