Converting - Explicit

All explicit data type conversion must be done using a Data Type Conversion Function.
All the conversion functions can automatically handle locale issues
That means that they will take international date/time and number regional settings into account.


Double to Integer

Dim myDouble As Double 
Dim myInteger As Integer
myDouble = 10.6
myInteger = CInt(myDouble)
Debug.Print myInteger // 11

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).
CCHAROnly available in VB.Net
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 variant/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.
CLNGPTRReturns the expression converted to a longptr data type.
COBJOnly available in VB.Net
CSBYTEOnly available in VB.Net
CSHORTOnly available in VB.Net
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 variant/date subtype (Variant).
CVERRReturns the corresponding to a given error number (Variant).

Backwards Compatibility

These are only included for backwards compatibility and should not to used.
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.

INT*Returns the number rounded down to the nearest integer (Double).
STR*Returns the text string of a number (String).

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