Chr, Chr$ Functions
See Also Example
Returns a one-character string whose ANSI code is the argument.
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 character set ANSI character codes in the range 0 to 31, inclusive, are the same as the standard, nonprintable ASCII codes. For example, Chr(10) returns a linefeed character. It can be used to force a new line when message strings are formatted with MsgBox or InputBox..
Str, Str$ Functions
Chr, Chr$ Function Example
The example uses the Chr function to create a variable that will insert a newline character as well as a variable containing letters from A through Z. Each time the line containing Chr is executed within the For...Next loop, another letter is appended to the Msg variable. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Dim I, J, Msg, NL ' Declare variables.
NL = Chr(10) ' Define newline.
For I = 1 to 2 ' Set 2 iterations.
For J = Asc("A") To Asc("Z") ' From A through Z.
Msg = Msg & Chr(J) ' Create a string.
Msg = Msg & NL ' Insert newline.
MsgBox Msg ' Display results.