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.

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 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.
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 - STR

The STR is only included for backwards compatibility and should not to used.
This function returns the text string of a number (String).
STR is globally fixed. It only recognizes the dot (.) as a decimal separator, regardless of the user's computer settings.
CSTR is internationally aware. It looks at the user's Windows regional settings. If your user is in Europe and uses commas for decimals, CStr will output a comma.

Dim resultStr As String 
Dim resultCStr As String

resultStr = Str(10) ' Returns " 10" (Notice the leading space!)
resultCStr = CStr(10) ' Returns "10" (No space)
resultStr = Str(-10) ' Returns "-10" (No leading space)

Not Available

CCHARThis is not available in VBA, only VB.Net
COBJThis is not available in VBA, only VB.Net
CSBYTEThis is not available in VBA, only VB.Net
CSHORTThis is not available in VBA, only VB.Net
CTypeThis is not available in VBA, only VB.Net
DirectCastThis is not available in VBA, only VB.Net
TryCastThis is not available in VBA, only VB.Net

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