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

Chr, ChrB, ChrW Functions

Syntax

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

Use: Required

Data Type: Long

An expression that evaluates to either an ANSI or Unicode character code.

Return Value

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

Description

Returns the character represented by charactercode.

Rules at a Glance

  • Chr returns the character associated with an ANSI character code.

  • ChrB returns a one-byte string.

  • ChrW returns a Unicode character.

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)
  • You can use the ChrB function to assign binary values to String variables.

  • The following table lists some of the more commonly used character codes that are supplied in the call to the Chr function:

Code

Value

Description

0

NULL

For C/C++ string functions, the null character required to terminate standard strings; equivalent to the vbNullChar constant.

9

TAB

Equivalent to the vbTab constant.

10

LF

Equivalent to the vbLf constant.

13

CR

Equivalent to the vbCr constant.

13 & 10

CRLF

Equivalent to the CWlocal constant.

34

"

Quotation mark. Useful to embed quotation marks within a literal string, especially when forming SQL query strings.

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