Chr Function

傳回與指定字元代碼對應的字元。

Syntax:


      Chr[$](charcode As Integer) As String
    

Return value:

String

Parameters:

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.


Example:


        Sub ExampleChr
            REM 此示例在字串中插入問號 (ASCII 值為 34)。
            MsgBox "A " + Chr$(34) + "short" + Chr(34) + " trip."
            REM 對話方塊中顯示的輸出為:A "short" trip。
            MsgBox Chr(charcode := 64) ' "@" sign
        End Sub
    

Please support us!