Name
CStr Function
Named Arguments
No
Syntax
CStr(expression
)
-
expression
(required; any) Any numeric, date, string, or Boolean expression
Return Value
expression
converted to a string
Description
Returns a string representation of
expression
Rules at a Glance
If expression
is Boolean, the function
returns one of the strings "True"
or
"False"
. For an expression that can be interpreted
as a date, the return value is a string representation of that date,
in the short date format of the host computer. For a numeric
expression, the return is a string representing the number.
Example
Dim sMyString as String sMyString = CStr(100)
Programming Tips and Gotchas
The string representation of Boolean values is either
"True"
or"False"
, as opposed to their underlying values of 0 and -1.Uninitialized numeric data types passed to CStr return “0.”
An uninitialized date variable passed to CStr returns “12:00:00AM.”
Like most of the conversion functions, CStr is not actually a function in the Microsoft.VisualBasic namespace. Instead, it is similar to a Visual C++ macro; the compiler translates the function call into inline code.
See Also
Get VB.NET Language in a Nutshell, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.