Chr, Chr$, ChrB, ChrB$, ChrW Functions

Named Arguments

No

Syntax

Chr(charactercode)
Chr$(charactercode)
ChrB(charactercode)
ChrB$(charactercode)
ChrW(charactercode)

charactercode

Use: Required

Data Type: Long

An expression that evaluates to either an ASCII or DBCS character code.

Return Value

Chr, ChrB, and ChrW return a variant of the string subtype that contains the character represented by charactercode.

Chr$ and ChrB$ return a string containing the character represented by charactercode.

Description

Returns the character represented by charactercode.

Rules at a Glance

  • Chr and Chr$ return the character associated with an ASCII or ANSI character code.

  • ChrB and ChrB$ return a one-byte string variant or a one-byte string, respectively.

  • ChrW returns a Unicode character; however, on systems that don't support the Unicode character set, the function behaves identically to the Chr function.

Programming Tips and Gotchas

  • Use Chr(34) to embed quotation marks inside a string, as shown in the following example:

    sSQL = "SELECT * FROM myTable _
           where myColumn = " & Chr(34) & sValue & Chr(34)
  • It's up to you as the programmer to decide which variation of the function to use—that is, whether to use the string or variant version of the function. The String versions, Chr$ and ChrB$ use less memory than their variant counterparts; however, you may find the variant versions more flexible, since they convert data types automatically and handle Null values more cleanly.

  • You can use the ChrB

Get VB & VBA in a Nutshell: The Language now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.