Chr Function

Returnerar det tecken som motsvarar teckenkoden.

Syntax:

Chr[$](expression As Integer) As String

Returnerat värde:

String

Parametrar:

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.


Du kan t.ex. använda funktionen Chr$ för att skicka styrkoder till en skrivare eller annan kringutrustning. Du kan också använda funktionen för att lägga till citattecken i en sträng.

Felkoder:

5 Felaktigt proceduranrop

6 Spill

note

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


Exempel:


        Sub ExampleChr
            ' I det här exemplet infogas citattecken (ASCII-värde 34) i en sträng
            MsgBox "A "+ Chr$(34)+"short" + Chr(34)+" trip."
            ' Texten i dialogrutan blir: En "kort" resa
        End Sub