Chr Function

返回与指定字符代码对应的字符。

语法:


      Chr[$](charcode As Integer) As String
    

返回值:

String

参数:

charcode: a numeric expression that represents a valid 8-bit ASCII value (0-255) or a 16-bit Unicode value. (To support expressions with a nominally negative argument like Chr(&H8000) in a backwards-compatible way, values in the range −32768 to −1 are internally mapped to the range 32768 to 65535.)

warning

When VBA compatibility mode is enabled (Option VBASupport 1), charcode is a numeric expression that represents a valid 8-bit ASCII value (0-255) only.


利用「Chr$」函数,可以将特殊的控制序列发送到打印机或其他输出源。还可以利用该函数在字符串表达式中插入引号。

错误代码:

5 无效的过程调用

6 溢出

note

An overflow error will occur when VBA compatibility mode is enabled and the expression value is greater than 255.


示例:


        Sub ExampleChr
            ' 此示例在字符串中插入引号 (ASCII 值为 34)。
            MsgBox "A " + Chr$(34) + "short" + Chr(34) + " trip."
            ' 对话框中的输出为: A "short" trip。
            MsgBox Chr(charcode := 64) ' "@" sign
        End Sub
    

请支持我们!