O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

Str Function

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required