contents.gifindex.gifprev1.gifnext1.gif

Chr, Chr$

Purpose

Returns a one-character string whose ANSI code is the argument.

Arguments

Chr[$]( charcode )

Notes

Chr returns a Variant; Chr$ returns a String. The argument charcode is an integer between 0 and 255, inclusive. Applications for Microsoft Windows use the ANSI charcter set. ANSI character codes in the range 0 to 31, inclusive, are the same as the standard, nonprintable ASCII codes. For example, Chr(13) returns a carriage-return character, and Chr(10) returns a linefeed character. Together they can be used to force a new line when message strings are formatted with MsgBox or InputBox.

Example

This example uses the Chr function to create a variable containing letters from A through Z. The number 64 in the argument to the Chr function is the ANSI code for the character preceding the letter A. Each time the line containing Chr is executed, another letter is added to Alphabet.

For I = 1 To 26
// Twenty-six characters.
Alphabet = Alphabet & Chr( 64 + I )
// Create a string.
Next I