Chr Function

Mengembalikan karakter yang sesuai dengan kode karakter yang ditentukan.

Sintaksis:

Chr[$](expression As Integer) As String

Nilai balikan:

String

Parameter:

Expression: 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), Expression is a numeric expression that represents a valid 8-bit ASCII value (0-255) only.


Gunakan Chr$ berfungsi untuk mengirim urutan kontrol khusus ke printer atau ke sumber output lain. Anda juga dapat menggunakannya untuk menyisipkan tanda kutip dalam ekspresi string.

Kode kesalahan:

5 Tidak sah dalam pemanggilan prosedur

6 Tumpang tindih

note

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


Contoh:


        Sub ExampleChr
            ' Contoh ini memasukkan tanda kutip (nilai ASCII 34) dalam sebuah string.
            MsgBox "A "+ Chr$(34)+"short" + Chr(34)+" trip."
            ' Cetakan muncul dalam dialog sebagai: Perjalanan "singkat".
        End Sub