CStr Function

Named Arguments

No

Syntax

CStr(expression)

expression

Use: Required

Data Type: Any

Any expression that evaluates 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.

  • CStr is equivalent to the older Str function.

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 and –1.

  • Uninitialized numeric data types passed to CStr return "0".

  • An uninitialized date variable passed to CStr returns "12:00:00AM."

See Also

Format Function, Str Function, Chapter 3

Get VB & VBA in a Nutshell: The Language 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.