Chr Function

Returns the character associated with the specified ANSI character code.

Syntax

Chr(charcode)

Remarks

The charcode argument is a number that identifies a character. Numbers from 0 to 31 are the same as standard, nonprintable ASCII codes. For example, Chr(10) returns a linefeed character.

The following example uses the Chr function to return the character associated with the specified character code:

The following example illustrates the use of the Chr function:

Example 1:

Dim MyChar
MyChar = Chr(65)   ' Returns 'A'.
'Output: 'A’

Example 2:

MyChar = Chr(97)   ' Returns 'a'.
'Output: 'a’

Example 3:

MyChar = Chr(62)   ' Returns '>'.
'Output: '>’

Example 4:

MyChar = Chr(37)   ' Returns '%'.
'Output: '%’

Example 5:

Dim LineFeed, CarriageReturn
LineFeed = Chr(10)   ' Returns a linefeed character.
CarriageReturn = Chr(13)   ' Returns a carriage return character.
'LineFeed contains value as Line Feed
'CarriageReturn contains value as Carriage Return

Example 6:

Dim CombinedChars
CombinedChars = Chr(72) & Chr(101) & Chr(108) & Chr(108) & Chr(111)   ' Returns 'Hello'.
'Output: "Hello"

Example 7:

Dim SpecialChar
SpecialChar = Chr(64)  
'Output: '@’

Example 8:

SpecialChar = Chr(35)    ' Returns '#'.
'Output: '#’

Example 9:

Dim WelcomeMessage
WelcomeMessage = "Welcome" & Chr(32) & "to" & Chr(32) & "VBScript!"   ' Inserts space using Chr(32).
'Output: "Welcome to VBScript!"