Name

CStr Function

Syntax

CStr(expression)
expression

Use: Required

Data Subtype: Any

Any expression that evaluates to a string.

Return Value

expression converted to a Variant with a String subtype.

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 as String
SMyString = CStr(100)

Programming Tips & Gotchas

  • The string representation of Boolean values is either True or False, as opposed to their underlying values of and -1.

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

Get VBScript in a Nutshell 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.