Name
Chr, ChrB, ChrW Functions
Syntax
Chr(charactercode) ChrB(charactercode) ChrW(charactercode)
-
charactercode Use: Required
Data Subtype: Long
An expression that evaluates to either an ASCII or DBCS character code.
Return Value
Chr, ChrB, and
ChrW return a variant of the string subtype that
contains the character represented by
charactercode
.
Description
Returns the character represented by
charactercode.
Rules at a Glance
Chrreturns the character associated with an ASCII or ANSI character code.ChrBreturns a one-byte string variant or a one-byte string, respectively.ChrWreturns a Unicode character; however, on systems that don’t support the Unicode character set, the function behaves identically toChr.
Programming Tips & Gotchas
Use
Chr(34)to embed quotation marks inside a string, as shown in the following example:sSQL = "SELECT * from myTable where myColumn = " & Chr(34) & _ sValue & Chr(34)You can use the
ChrBfunction to assign binary values to String variables. Try this little demonstration of outputting a Unicode character (Unicode characters are two bytes in length; for example, “F” is represented by binary 70 and binary 0):Dim sBinVar sBinVar = ChrB(70) & ChrB(0) MsgBox BinVar
You can use the
ChrWfunction to return Unicode characters. Try this code to produce a Unicode “G”:Dim sBinVar sBinVar = ChrW(AscW("G")) MsfBox sBinVarWell, wasn’t that exciting? A “G” was displayed in the message dialog! The difference is that the character displayed is a Unicode “G”.
The following ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access