O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

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

Syntax

CStr(expression)
expression

Use: Required

Data Type: Any

Any expression that is to be converted to a string.

Return Value

expression converted to a String.

Description

Returns a string representation of expression.

Rules at a Glance

Almost any data can be passed to CStr to be converted to a string.

Example

Dim sMyString
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.

  • An uninitialized variable passed to CStr returns an empty string.

  • An object reference cannot be passed to the CStr function. Attempting to do so generates a runtime error.

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