vb6parse 1.0.0

vb6parse is a library for parsing and analyzing VB6 code, from projects, to controls, to modules, and forms.
Documentation
<!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 - chrb_dollar - String">
    <title>chrb_dollar - 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> / chrb_dollar</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="chrb-function">ChrB$ Function</h1>
<p>Returns a <code>String</code> containing the character associated with the specified ANSI character code.
The dollar sign suffix (<code>$</code>) explicitly indicates that this function returns a <code>String</code> type
(not a <code>Variant</code>), and the "B" suffix indicates this is the byte (ANSI) version.</p>
<h2 id="syntax">Syntax</h2>
<pre><code class="language-vbnet">ChrB$(charcode)</code></pre>
<h2 id="parameters">Parameters</h2>
<ul>
<li><strong><code>charcode</code></strong>: Required. <code>Long</code> value that identifies a character in the ANSI character set.
  Valid values are 0-255. For values outside this range, an error occurs.</li>
</ul>
<h2 id="return-value">Return Value</h2>
<p>Returns a <code>String</code> containing the single byte character corresponding to the specified ANSI code.
The return value is always a <code>String</code> type (never <code>Variant</code>), and represents a single-byte
character from the ANSI character set.</p>
<h2 id="remarks">Remarks</h2>
<ul>
<li>The <code>ChrB$</code> function combines the behavior of <code>ChrB</code> (byte character) with the <code>$</code> suffix
  (explicit <code>String</code> return type).</li>
<li>Valid range: 0-255 (Error 5 "Invalid procedure call or argument" for values outside range).</li>
<li><code>ChrB$(0)</code> returns a null character.</li>
<li><code>ChrB$(13)</code> returns carriage return (<code>vbCr</code>).</li>
<li><code>ChrB$(10)</code> returns line feed (<code>vbLf</code>).</li>
<li><code>ChrB$(9)</code> returns tab character (<code>vbTab</code>).</li>
<li>Values 0-31 are non-printable control characters.</li>
<li>Values 32-126 are standard printable ASCII characters.</li>
<li>Values 127-255 depend on the system code page (often Windows-1252 in VB6).</li>
<li>The inverse function is <code>AscB</code>, which returns the numeric byte value of a character.</li>
<li>For better performance when you know the result is a string, use <code>ChrB$</code> instead of <code>ChrB</code>.</li>
</ul>
<h2 id="common-character-codes">Common Character Codes</h2>
<table>
<thead>
<tr>
<th>Code</th>
<th>Character</th>
<th>Constant</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>(null)</td>
<td><code>vbNullChar</code></td>
<td>Null character</td>
</tr>
<tr>
<td>9</td>
<td>\t</td>
<td><code>vbTab</code></td>
<td>Horizontal tab</td>
</tr>
<tr>
<td>10</td>
<td>\n</td>
<td><code>vbLf</code></td>
<td>Line feed</td>
</tr>
<tr>
<td>13</td>
<td>\r</td>
<td><code>vbCr</code></td>
<td>Carriage return</td>
</tr>
<tr>
<td>32</td>
<td>(space)</td>
<td>-</td>
<td>Space character</td>
</tr>
<tr>
<td>34</td>
<td>"</td>
<td>-</td>
<td>Double quote</td>
</tr>
<tr>
<td>39</td>
<td>'</td>
<td>-</td>
<td>Single quote</td>
</tr>
<tr>
<td>65</td>
<td>A</td>
<td>-</td>
<td>Uppercase A</td>
</tr>
<tr>
<td>97</td>
<td>a</td>
<td>-</td>
<td>Lowercase a</td>
</tr>
</tbody>
</table>
<h2 id="typical-uses">Typical Uses</h2>
<ol>
<li><strong>Building ANSI strings</strong> - Construct strings from byte values</li>
<li><strong>Line breaks</strong> - Insert carriage returns and line feeds</li>
<li><strong>Special characters</strong> - Add tabs, quotes, and other special characters</li>
<li><strong>Byte-level operations</strong> - Work with binary data or legacy file formats</li>
<li><strong>ANSI text generation</strong> - Create strings for systems expecting ANSI encoding</li>
<li><strong>Legacy protocol support</strong> - Work with older communication protocols</li>
<li><strong>Control characters</strong> - Generate non-printable control characters</li>
</ol>
<h2 id="basic-examples">Basic Examples</h2>
<pre><code class="language-vbnet">&#x27; Example 1: Get character from code
Dim ch As String
ch = ChrB$(65)  &#x27; Returns &quot;A&quot;</code></pre>
<pre><code class="language-vbnet">&#x27; Example 2: Lowercase letter
Dim lower As String
lower = ChrB$(97)  &#x27; Returns &quot;a&quot;</code></pre>
<pre><code class="language-vbnet">&#x27; Example 3: Special character
Dim space As String
space = ChrB$(32)  &#x27; Returns &quot; &quot;</code></pre>
<pre><code class="language-vbnet">&#x27; Example 4: Line break
Dim msg As String
msg = &quot;Line 1&quot; &amp; ChrB$(13) &amp; ChrB$(10) &amp; &quot;Line 2&quot;</code></pre>
<h2 id="common-patterns">Common Patterns</h2>
<h3 id="multi-line-strings">Multi-line Strings</h3>
<pre><code class="language-vbnet">Function CreateMultiLine() As String
    Dim result As String
    result = &quot;First Line&quot; &amp; ChrB$(13) &amp; ChrB$(10)
    result = result &amp; &quot;Second Line&quot; &amp; ChrB$(13) &amp; ChrB$(10)
    result = result &amp; &quot;Third Line&quot;
    CreateMultiLine = result
End Function</code></pre>
<h3 id="tab-separated-values">Tab-Separated Values</h3>
<pre><code class="language-vbnet">Function CreateTSV(col1 As String, col2 As String, col3 As String) As String
    CreateTSV = col1 &amp; ChrB$(9) &amp; col2 &amp; ChrB$(9) &amp; col3
End Function</code></pre>
<h3 id="build-string-from-byte-array">Build String from Byte Array</h3>
<pre><code class="language-vbnet">Function BytesToString(bytes() As Byte) As String
    Dim i As Integer
    Dim result As String
    For i = LBound(bytes) To UBound(bytes)
        result = result &amp; ChrB$(bytes(i))
    Next i
    BytesToString = result
End Function</code></pre>
<h3 id="quote-in-string">Quote in String</h3>
<pre><code class="language-vbnet">Function AddQuotes(text As String) As String
    AddQuotes = ChrB$(34) &amp; text &amp; ChrB$(34)
End Function</code></pre>
<h3 id="null-terminated-string">Null-Terminated String</h3>
<pre><code class="language-vbnet">Function CreateNullTerminated(text As String) As String
    CreateNullTerminated = text &amp; ChrB$(0)
End Function</code></pre>
<h3 id="ansi-protocol-message">ANSI Protocol Message</h3>
<pre><code class="language-vbnet">Function CreateProtocolMessage(msgType As Byte, data As String) As String
    Dim msg As String
    &#x27; SOH (Start of Header)
    msg = ChrB$(1)
    &#x27; Message type
    msg = msg &amp; ChrB$(msgType)
    &#x27; STX (Start of Text)
    msg = msg &amp; ChrB$(2)
    &#x27; Payload
    msg = msg &amp; data
    &#x27; ETX (End of Text)
    msg = msg &amp; ChrB$(3)
    CreateProtocolMessage = msg
End Function</code></pre>
<h3 id="generate-alphabet">Generate Alphabet</h3>
<pre><code class="language-vbnet">Function GenerateAlphabet() As String
    Dim i As Integer
    Dim result As String
    For i = 65 To 90
        result = result &amp; ChrB$(i)
    Next i
    GenerateAlphabet = result  &#x27; Returns &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;
End Function</code></pre>
<h3 id="csv-field-with-quotes">CSV Field with Quotes</h3>
<pre><code class="language-vbnet">Function QuoteCSVField(field As String) As String
    Dim quoted As String
    &#x27; Replace &quot; with &quot;&quot;
    quoted = Replace(field, ChrB$(34), ChrB$(34) &amp; ChrB$(34))
    QuoteCSVField = ChrB$(34) &amp; quoted &amp; ChrB$(34)
End Function</code></pre>
<h3 id="password-mask">Password Mask</h3>
<pre><code class="language-vbnet">Function MaskPassword(length As Integer) As String
    Dim i As Integer
    Dim result As String
    For i = 1 To length
        result = result &amp; ChrB$(42)  &#x27; Asterisk
    Next i
    MaskPassword = result
End Function</code></pre>
<h3 id="character-range">Character Range</h3>
<pre><code class="language-vbnet">Function GetPrintableChars() As String
    Dim i As Integer
    Dim result As String
    For i = 32 To 126
        result = result &amp; ChrB$(i)
    Next i
    GetPrintableChars = result
End Function</code></pre>
<h2 id="related-functions">Related Functions</h2>
<ul>
<li><code>ChrB</code>: Returns byte character as <code>Variant</code> instead of <code>String</code></li>
<li><code>Chr$</code>: Returns ANSI/Unicode character (system dependent)</li>
<li><code>ChrW$</code>: Returns Unicode character (2 bytes)</li>
<li><code>AscB</code>: Returns byte value of first byte in string (inverse of <code>ChrB$</code>)</li>
<li><code>AscB$</code>: Not a valid function (there is no <code>AscB$</code>)</li>
</ul>
<h2 id="error-handling">Error Handling</h2>
<pre><code class="language-vbnet">Function SafeChrB(code As Long) As String
    On Error Resume Next
    SafeChrB = ChrB$(code)
    If Err.Number &lt;&gt; 0 Then
        SafeChrB = &quot;&quot;
        Err.Clear
    End If
End Function</code></pre>
<h2 id="performance-considerations">Performance Considerations</h2>
<ul>
<li><code>ChrB$</code> is slightly more efficient than <code>ChrB</code> because it avoids <code>Variant</code> overhead</li>
<li>For building strings from many bytes, consider using a buffer or byte array</li>
<li>Concatenating many <code>ChrB$</code> calls can be slow; use arrays and <code>Join</code> for better performance</li>
<li>When working with large amounts of byte data, consider <code>String</code> function or byte arrays</li>
</ul>
<h2 id="best-practices">Best Practices</h2>
<ol>
<li>Use named constants for common control characters instead of magic numbers</li>
<li>Validate character codes are in the range 0-255 before calling <code>ChrB$</code></li>
<li>Use <code>ChrB$</code> for ANSI/byte operations, <code>ChrW$</code> for Unicode operations</li>
<li>Document when using non-printable characters (codes 0-31)</li>
<li>Consider code page issues when working with extended ANSI (128-255)</li>
<li>Use <code>vbCrLf</code> constant instead of <code>ChrB$(13) &amp; ChrB$(10)</code> when possible</li>
<li>Prefer <code>ChrB$</code> over <code>ChrB</code> when you need a <code>String</code> result</li>
</ol>
<h2 id="limitations">Limitations</h2>
<ul>
<li>Limited to character codes 0-255 (use <code>ChrW$</code> for full Unicode support)</li>
<li>Character interpretation depends on system code page for values 128-255</li>
<li>Does not validate that the resulting character is printable</li>
<li>No direct support for multi-byte Unicode characters</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>&copy; 2024-2026 VB6Parse Contributors. Licensed under the MIT License.</p>
        </div>
    </footer>
</body>
</html>