<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="VB6Parse Library Reference - chrw - String">
<title>chrw - String - VB6Parse Library Reference</title>
<link rel="stylesheet" href="../../../assets/css/style.css">
<link rel="stylesheet" href="../../../assets/css/docs-style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css">
<script src="../../../assets/js/theme-switcher.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/vbnet.min.js"></script>
<script>hljs.highlightAll();</script>
</head>
<body>
<header class="docs-header">
<div class="container">
<h1><a href="../../../index.html">VB6Parse</a> / <a href="../../../library/index.html">Library</a> / <a href="../../../library/functions/string/index.html">String</a> / chrw</h1>
<p class="tagline">VB6 Library Reference</p>
</div>
</header>
<nav class="docs-nav">
<div class="container">
<a href="../../../index.html">Home</a>
<a href="../../../library/index.html">Library Reference</a>
<a href="../../../documentation.html">Documentation</a>
<a href="https://docs.rs/vb6parse" target="_blank">API Docs</a>
<a href="https://github.com/scriptandcompile/vb6parse" target="_blank">GitHub</a>
<button id="theme-toggle" class="theme-toggle" aria-label="Toggle theme">
<span class="theme-icon">🌙</span>
</button>
</div>
</nav>
<main class="container">
<article class="library-item">
<h1 id="chrw-function">ChrW Function</h1>
<p>Returns a <code>String</code> containing the Unicode character associated with the specified character code.
The "W" suffix indicates this is the wide (Unicode) version of the <code>Chr</code> function.</p>
<h2 id="syntax">Syntax</h2>
<pre><code class="language-vbnet">ChrW(charcode)</code></pre>
<h2 id="parameters">Parameters</h2>
<ul>
<li><strong>charcode</strong>: Required. <code>Long</code>. A numeric expression that identifies a Unicode character.
Valid values are -32768 to 65535. However, values -32768 to -1 are treated as 65536 + value.</li>
</ul>
<h2 id="returns">Returns</h2>
<p>Returns a <code>String</code> containing a single Unicode character corresponding to the specified code.</p>
<h2 id="remarks">Remarks</h2>
<ul>
<li><code>ChrW</code> is used to return Unicode characters (wide characters).</li>
<li>The W suffix stands for "Wide", distinguishing it from the ANSI <code>ChrB</code> function.</li>
<li>Valid Unicode code points range from 0 to 65535 (0x0000 to 0xFFFF) in the Basic Multilingual Plane.</li>
<li>Negative values from -32768 to -1 are converted by adding 65536, allowing access to the full range.</li>
<li><code>ChrW</code> is essential for working with international characters, symbols, and emoji within the BMP.</li>
<li>For ANSI characters (0-255), <code>ChrW</code> and <code>Chr</code> produce the same results on systems using single-byte character sets.</li>
<li>Characters outside the Basic Multilingual Plane (above 65535) require surrogate pairs in VB6.</li>
<li>If charcode is outside the valid range, a runtime error occurs (Error 5: Invalid procedure call or argument).</li>
</ul>
<h2 id="typical-uses">Typical Uses</h2>
<ol>
<li><strong>International text support</strong> - Create strings with characters from various languages</li>
<li><strong>Unicode symbol insertion</strong> - Insert mathematical symbols, currency symbols, arrows, etc.</li>
<li><strong>XML/HTML entity handling</strong> - Convert numeric character references to actual characters</li>
<li><strong>Special character creation</strong> - Generate Unicode control characters and formatting marks</li>
<li><strong>Cross-platform text</strong> - Ensure consistent character representation across different systems</li>
<li><strong>Unicode file processing</strong> - Read and write Unicode text files correctly</li>
<li><strong>Internationalization (i18n)</strong> - Support multiple languages in applications</li>
</ol>
<h2 id="basic-examples">Basic Examples</h2>
<pre><code class="language-vbnet">' Example 1: Simple Unicode character
Dim ch As String
ch = ChrW(65) ' Returns "A" (same as Chr for ASCII range)</code></pre>
<pre><code class="language-vbnet">' Example 2: Euro symbol
Dim euro As String
euro = ChrW(8364) ' Returns "€"</code></pre>
<pre><code class="language-vbnet">' Example 3: Greek letter
Dim alpha As String
alpha = ChrW(945) ' Returns "α" (Greek small letter alpha)</code></pre>
<pre><code class="language-vbnet">' Example 4: Chinese character
Dim hanzi As String
hanzi = ChrW(20013) ' Returns "中" (Chinese character for "middle")</code></pre>
<h2 id="common-patterns">Common Patterns</h2>
<h3 id="unicode-line-separator">Unicode Line Separator</h3>
<pre><code class="language-vbnet">Const UNICODE_LINE_SEP = 8232
text = "Line 1" & ChrW(UNICODE_LINE_SEP) & "Line 2"</code></pre>
<h3 id="bullet-point-list">Bullet Point List</h3>
<pre><code class="language-vbnet">Dim bullet As String
bullet = ChrW(8226) ' "•"
list = bullet & " Item 1" & vbCrLf & bullet & " Item 2"</code></pre>
<h3 id="copyright-symbol">Copyright Symbol</h3>
<pre><code class="language-vbnet">Dim copyright As String
copyright = ChrW(169) ' "©"
notice = "Copyright " & copyright & " 2025"</code></pre>
<h3 id="mathematical-symbols">Mathematical Symbols</h3>
<pre><code class="language-vbnet">Dim infinity As String, pi As String
infinity = ChrW(8734) ' "∞"
pi = ChrW(960) ' "π"
equation = pi & " " & ChrW(8776) & " 3.14" ' "π ≈ 3.14"</code></pre>
<h3 id="arrow-symbols">Arrow Symbols</h3>
<pre><code class="language-vbnet">Dim rightArrow As String
rightArrow = ChrW(8594) ' "→"
leftArrow = ChrW(8592) ' "←"</code></pre>
<h3 id="non-breaking-space">Non-Breaking Space</h3>
<pre><code class="language-vbnet">Dim nbsp As String
nbsp = ChrW(160) ' Non-breaking space
text = "Price:" & nbsp & "$100"</code></pre>
<h3 id="emoji-and-symbols-bmp-only">Emoji and Symbols (BMP only)</h3>
<pre><code class="language-vbnet">Dim heart As String, star As String
heart = ChrW(9829) ' "♥"
star = ChrW(9733) ' "★"</code></pre>
<h3 id="zero-width-characters">Zero-Width Characters</h3>
<pre><code class="language-vbnet">Dim zwj As String
zwj = ChrW(8205) ' Zero-width joiner</code></pre>
<h3 id="currency-symbols">Currency Symbols</h3>
<pre><code class="language-vbnet">Dim pound As String, yen As String
pound = ChrW(163) ' "£"
yen = ChrW(165) ' "¥"</code></pre>
<h3 id="diacritical-marks">Diacritical Marks</h3>
<pre><code class="language-vbnet">Dim acute As String
acute = ChrW(180) ' "´" (acute accent)
combined = "e" & ChrW(769) ' Combining acute accent</code></pre>
<h2 id="advanced-examples">Advanced Examples</h2>
<h3 id="building-multilingual-text">Building Multilingual Text</h3>
<pre><code class="language-vbnet">Function GetGreeting(language As String) As String
Select Case language
Case "chinese"
GetGreeting = ChrW(20320) & ChrW(22909) ' "你好"
Case "japanese"
GetGreeting = ChrW(12371) & ChrW(12435) & ChrW(12395) & ChrW(12385) & ChrW(12399) ' "こんにちは"
Case "korean"
GetGreeting = ChrW(50504) & ChrW(45397) & ChrW(54616) & ChrW(49464) & ChrW(50836) ' "안녕하세요"
Case "russian"
GetGreeting = ChrW(1055) & ChrW(1088) & ChrW(1080) & ChrW(1074) & ChrW(1077) & ChrW(1090) ' "Привет"
Case Else
GetGreeting = "Hello"
End Select
End Function</code></pre>
<h3 id="html-entity-decoder">HTML Entity Decoder</h3>
<pre><code class="language-vbnet">Function DecodeNumericEntity(entity As String) As String
' Decode &#nnnn; or &#xhhhh; entities
Dim code As Long
If InStr(entity, "&#x") > 0 Then
' Hexadecimal entity
code = CLng("&H" & Mid(entity, 4, Len(entity) - 4))
ElseIf InStr(entity, "&#") > 0 Then
' Decimal entity
code = CLng(Mid(entity, 3, Len(entity) - 3))
End If
If code >= 0 And code <= 65535 Then
DecodeNumericEntity = ChrW(code)
End If
End Function</code></pre>
<h3 id="unicode-range-validator">Unicode Range Validator</h3>
<pre><code class="language-vbnet">Function IsInUnicodeRange(char As String, rangeStart As Long, rangeEnd As Long) As Boolean
If Len(char) = 0 Then Exit Function
Dim code As Long
code = AscW(char)
IsInUnicodeRange = (code >= rangeStart And code <= rangeEnd)
End Function
' Example usage:
' If IsInUnicodeRange(char, 0x4E00, 0x9FFF) Then
' Debug.Print "CJK Unified Ideograph"
' End If</code></pre>
<h3 id="unicode-text-file-writer">Unicode Text File Writer</h3>
<pre><code class="language-vbnet">Sub WriteUnicodeFile(filename As String, text As String)
Dim fso As Object, stream As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set stream = CreateObject("ADODB.Stream")
stream.Type = 2 ' Text
stream.Charset = "UTF-8"
stream.Open
' Add BOM for UTF-8
stream.WriteText ChrW(65279) ' UTF-8 BOM
stream.WriteText text
stream.SaveToFile filename, 2
stream.Close
End Sub</code></pre>
<h2 id="error-handling">Error Handling</h2>
<pre><code class="language-vbnet">Function SafeChrW(charcode As Long) As String
On Error GoTo ErrorHandler
' Normalize negative values
If charcode < 0 Then
charcode = 65536 + charcode
End If
If charcode >= 0 And charcode <= 65535 Then
SafeChrW = ChrW(charcode)
Else
SafeChrW = "?" ' Replacement character for invalid codes
End If
Exit Function
ErrorHandler:
SafeChrW = "?"
End Function</code></pre>
<h2 id="performance-notes">Performance Notes</h2>
<ul>
<li><code>ChrW</code> is a fast operation with minimal overhead</li>
<li>When building long Unicode strings, use string concatenation efficiently or a <code>StringBuilder</code> pattern</li>
<li>For repeated character creation, consider caching the result</li>
<li><code>AscW</code> is the inverse function of <code>ChrW</code></li>
</ul>
<h2 id="best-practices">Best Practices</h2>
<ol>
<li><strong>Use <code>ChrW</code> for Unicode</strong> - Always use <code>ChrW</code> instead of <code>Chr</code> when working with international text</li>
<li><strong>Validate ranges</strong> - Check that character codes are within valid Unicode ranges</li>
<li><strong>Handle errors</strong> - Wrap <code>ChrW</code> calls in error handlers when processing user input</li>
<li><strong>Document character codes</strong> - Use constants or comments to explain non-obvious character codes</li>
<li><strong>Test with actual data</strong> - Verify Unicode text displays correctly in target environments</li>
<li><strong>Consider normalization</strong> - Be aware that some characters can be represented multiple ways</li>
<li><strong>Use UTF-8 for files</strong> - When saving Unicode text, prefer UTF-8 encoding</li>
</ol>
<h2 id="comparison-with-related-functions">Comparison with Related Functions</h2>
<table>
<thead>
<tr>
<th>Function</th>
<th>Character Set</th>
<th>Range</th>
<th>Use Case</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Chr</code></td>
<td>System default (ANSI/Unicode)</td>
<td>0-255</td>
<td>Legacy code, simple ASCII</td>
</tr>
<tr>
<td><code>ChrB</code></td>
<td>ANSI (byte)</td>
<td>0-255</td>
<td>ANSI text, byte operations</td>
</tr>
<tr>
<td><code>ChrW</code></td>
<td>Unicode (wide)</td>
<td>0-65535</td>
<td>International text, symbols</td>
</tr>
<tr>
<td><code>AscW</code></td>
<td>Unicode (inverse)</td>
<td>Returns 0-65535</td>
<td>Get Unicode code from character</td>
</tr>
</tbody>
</table>
<h2 id="unicode-ranges-reference">Unicode Ranges Reference</h2>
<p>Some common Unicode ranges that work with <code>ChrW</code>:
- <strong>Basic Latin</strong>: 0-127 (ASCII)
- <strong>Latin-1 Supplement</strong>: 128-255
- <strong>Greek and Coptic</strong>: 880-1023
- <strong>Cyrillic</strong>: 1024-1279
- <strong>Hebrew</strong>: 1424-1535
- <strong>Arabic</strong>: 1536-1791
- <strong>CJK Unified Ideographs</strong>: 19968-40959
- <strong>Hangul Syllables</strong>: 44032-55203
- <strong>Currency Symbols</strong>: 8352-8399
- <strong>Mathematical Operators</strong>: 8704-8959
- <strong>Arrows</strong>: 8592-8703
- <strong>Box Drawing</strong>: 9472-9599</p>
<h2 id="platform-notes">Platform Notes</h2>
<ul>
<li>VB6 supports Unicode through <code>ChrW</code> but stores strings internally in the system's native format</li>
<li>On Windows NT-based systems, strings are stored as Unicode (UTF-16)</li>
<li>On Windows 95/98/ME, strings use ANSI encoding, which may cause issues with characters outside the current code page</li>
<li>When running on older systems, test thoroughly with non-ASCII characters</li>
<li>Modern Windows systems (XP and later) handle Unicode properly</li>
</ul>
<h2 id="limitations">Limitations</h2>
<ul>
<li><code>ChrW</code> only supports the Basic Multilingual Plane (BMP), code points 0-65535</li>
<li>Characters outside the BMP (like some emoji) require surrogate pairs in VB6</li>
<li>Surrogate pairs are complex and require combining two <code>ChrW</code> calls</li>
<li>Not all fonts support all Unicode characters; display depends on available fonts</li>
<li>Some Unicode features like combining characters may not render correctly in all VB6 controls</li>
</ul>
</article>
<div style="margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--border-color);">
<p>
<a href="index.html">← Back to String</a> |
<a href="../index.html">View all functions</a>
</p>
</div>
</main>
<footer>
<div class="container">
<p>© 2024-2026 VB6Parse Contributors. Licensed under the MIT License.</p>
</div>
</footer>
</body>
</html>