Chr Function

Description

Returns a String containing the character associated with the specified character code.

Syntax

Chr(charcode)

The required charcode argument is a Long that identifies a character.

Remarks

Numbers from 0 to 31 are the same as standard, nonprintable ASCII codes. For example, Chr(10) returns a linefeed character. The normal range for charcode is
0 – 255. However, on DBCS systems, the actual range for charcode is –32768 to 65536.

Note   The ChrB function is used with byte data contained in a String. Instead of returning a character, which may be one or two bytes, ChrB always returns a single byte. The ChrW function returns a String containing the Unicode character except on platforms where Unicode is not supported, in which case, the behavior is identical to the Chr function.

See Also

Asc function, Str function.

Example

This example uses the Chr function to return the character associated with the specified character code.

Dim MyChar
MyChar = Chr(65)                            ' Returns A.
MyChar = Chr(97)                            ' Returns a.
MyChar = Chr(62)                            ' Returns >.
MyChar = Chr(37)                            ' Returns %.
Example (Microsoft Excel)

This example fills list box one on Dialog1 with the letters A through Z.

For i = 65 To 90
    DialogSheets("Dialog1").ListBoxes(1).AddItem Text:=Chr(i)
Next i
This example creates a line break in a message box by using the Chr function.

msgText = "The current folder is:" & Chr(13) & CurDir()
MsgBox msgText