VBS tutorial: Functions – CSTR functions


CSTR function

Returns an expression that has been converted toStringSubtypeVariant


expressionArgument is any valid expression.


In general, you can write code using subtype conversion functions to show that the results of some operations should be represented as a specific data type rather than the default type. For example, useCStrForce the result to be expressed asString

CStrFunction to replaceStrFunction to transfer data from other data types toStringSubtypes are converted to internationally recognized formats. For example, the recognition of decimal separators depends on the locale of the system.

expressionDetermine the returned data according to the following table:

If expression is CSTR return
Boolean String containing true or false.
Date character string, including the system’s short date format date.
Null Runtime error.
Empty Zero lengthcharacter string (“”)。
Error character stringContains the word error followed by the error number.
Other values character string, including this number.

The following example usesCStrFunction to convert a number toString:

Dim mydouble, mystringmydouble = 437.324 'mydouble is a double value. Mystring = CSTR (mydouble) 'mystring contains "437.324".