vb6parse 1.0.0

vb6parse is a library for parsing and analyzing VB6 code, from projects, to controls, to modules, and forms.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
<!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 - string_function - String">
    <title>string_function - 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> / string_function</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">
            <p>VB6 String Function
The <code>String</code> function returns a string consisting of a repeating character.</p>
<h2 id="syntax">Syntax</h2>
<pre><code class="language-vbnet">String(number, character)</code></pre>
<h2 id="parameters">Parameters</h2>
<ul>
<li><code>number</code>: Required. Long integer specifying the length of the returned string. Must be between 0 and approximately 2 billion (limited by available memory).</li>
<li><code>character</code>: Required. Variant specifying the character code or string expression whose first character is used.</li>
<li>If <code>character</code> is a numeric value, it's treated as a character code (0-255)</li>
<li>If <code>character</code> is a string, only the first character is used</li>
</ul>
<h2 id="returns">Returns</h2>
<p>Returns a <code>Variant</code> (String) containing a string of length <code>number</code> composed of the repeating character.</p>
<h2 id="remarks">Remarks</h2>
<p>The <code>String</code> function creates strings filled with repeating characters:
- <strong>Character code</strong>: If <code>character</code> is numeric (0-255), it's interpreted as an ASCII/ANSI character code
- <strong>String argument</strong>: If <code>character</code> is a string, only the first character is used (rest is ignored)
- <strong>Empty string</strong>: If <code>number</code> is 0, returns an empty string ("")
- <strong>Negative number</strong>: Causes Error 5 (Invalid procedure call or argument)
- <strong>Performance</strong>: Very efficient for creating repeating character strings
- <strong>Common uses</strong>: Creating separators, padding, borders, rulers, progress bars
- <strong>Memory limit</strong>: <code>number</code> is limited by available memory (typically up to ~2 billion characters)
- <strong>Related function</strong>: <code>Space</code> function is equivalent to <code>String(n, 32)</code> or <code>String(n, " ")</code></p>
<h3 id="character-code-examples">Character Code Examples</h3>
<ul>
<li><code>String(5, 65)</code> returns "AAAAA" (65 is ASCII code for 'A')</li>
<li><code>String(3, 42)</code> returns "**<em>" (42 is ASCII code for '</em>')</li>
<li><code>String(10, 45)</code> returns "----------" (45 is ASCII code for '-')</li>
<li><code>String(4, 61)</code> returns "====" (61 is ASCII code for '=')</li>
</ul>
<h3 id="string-argument-examples">String Argument Examples</h3>
<ul>
<li><code>String(5, "A")</code> returns "AAAAA"</li>
<li><code>String(3, "*")</code> returns "***"</li>
<li><code>String(10, "-")</code> returns "----------"</li>
<li><code>String(3, "Hello")</code> returns "HHH" (only first character used)</li>
</ul>
<h2 id="typical-uses">Typical Uses</h2>
<ol>
<li><strong>Line Separators</strong>: Create horizontal lines for text output or reports</li>
<li><strong>Padding</strong>: Pad strings to specific widths for alignment</li>
<li><strong>Borders</strong>: Create box borders for text displays</li>
<li><strong>Progress Indicators</strong>: Build progress bars or loading indicators</li>
<li><strong>Masking</strong>: Create mask strings (asterisks for passwords)</li>
<li><strong>Rulers</strong>: Create ruler lines for text editors or debuggers</li>
<li><strong>Fill Characters</strong>: Initialize strings with specific fill characters</li>
<li><strong>Visual Markers</strong>: Create visual separators in console or debug output</li>
</ol>
<h2 id="basic-examples">Basic Examples</h2>
<h3 id="example-1-creating-line-separators">Example 1: Creating Line Separators</h3>
<pre><code class="language-vbnet">Dim separator As String
separator = String(50, &quot;-&quot;)     &#x27; &quot;--------------------------------------------------&quot;
separator = String(40, &quot;=&quot;)     &#x27; &quot;========================================&quot;
separator = String(30, &quot;*&quot;)     &#x27; &quot;******************************&quot;
separator = String(20, 45)      &#x27; &quot;--------------------&quot; (45 = &#x27;-&#x27;)</code></pre>
<h3 id="example-2-padding-strings">Example 2: Padding Strings</h3>
<pre><code class="language-vbnet">Dim text As String
Dim padded As String
text = &quot;Title&quot;
&#x27; Left padding with spaces
padded = String(10 - Len(text), &quot; &quot;) &amp; text  &#x27; &quot;     Title&quot;
&#x27; Right padding with dots
padded = text &amp; String(20 - Len(text), &quot;.&quot;)  &#x27; &quot;Title...............&quot;</code></pre>
<h3 id="example-3-creating-box-borders">Example 3: Creating Box Borders</h3>
<pre><code class="language-vbnet">Sub DrawBox(width As Integer)
    Dim topBottom As String
    Dim side As String
    topBottom = &quot;+&quot; &amp; String(width - 2, &quot;-&quot;) &amp; &quot;+&quot;
    side = &quot;|&quot; &amp; String(width - 2, &quot; &quot;) &amp; &quot;|&quot;
    Debug.Print topBottom
    Debug.Print side
    Debug.Print side
    Debug.Print topBottom
End Sub</code></pre>
<h3 id="example-4-progress-bar">Example 4: Progress Bar</h3>
<pre><code class="language-vbnet">Function CreateProgressBar(percent As Integer, width As Integer) As String
    Dim filled As Integer
    Dim empty As Integer
    filled = (percent * width) \ 100
    empty = width - filled
    CreateProgressBar = &quot;[&quot; &amp; String(filled, &quot;#&quot;) &amp; String(empty, &quot; &quot;) &amp; &quot;]&quot;
    &#x27; Example: [#####     ] for 50%
End Function</code></pre>
<h2 id="common-patterns">Common Patterns</h2>
<h3 id="pattern-1-create-horizontal-line">Pattern 1: Create Horizontal Line</h3>
<pre><code class="language-vbnet">Function HorizontalLine(width As Integer, Optional char As String = &quot;-&quot;) As String
    HorizontalLine = String(width, char)
End Function</code></pre>
<h3 id="pattern-2-center-text">Pattern 2: Center Text</h3>
<pre><code class="language-vbnet">Function CenterText(text As String, width As Integer) As String
    Dim padding As Integer
    Dim leftPad As Integer
    Dim rightPad As Integer
    If Len(text) &gt;= width Then
        CenterText = Left$(text, width)
        Exit Function
    End If
    padding = width - Len(text)
    leftPad = padding \ 2
    rightPad = padding - leftPad
    CenterText = String(leftPad, &quot; &quot;) &amp; text &amp; String(rightPad, &quot; &quot;)
End Function</code></pre>
<h3 id="pattern-3-pad-number-with-zeros">Pattern 3: Pad Number with Zeros</h3>
<pre><code class="language-vbnet">Function PadWithZeros(value As Long, totalWidth As Integer) As String
    Dim numStr As String
    numStr = CStr(value)
    If Len(numStr) &gt;= totalWidth Then
        PadWithZeros = numStr
    Else
        PadWithZeros = String(totalWidth - Len(numStr), &quot;0&quot;) &amp; numStr
    End If
End Function</code></pre>
<h3 id="pattern-4-create-table-row-separator">Pattern 4: Create Table Row Separator</h3>
<pre><code class="language-vbnet">Function TableSeparator(columnWidths() As Integer) As String
    Dim i As Integer
    Dim result As String
    result = &quot;+&quot;
    For i = LBound(columnWidths) To UBound(columnWidths)
        result = result &amp; String(columnWidths(i), &quot;-&quot;) &amp; &quot;+&quot;
    Next i
    TableSeparator = result
End Function</code></pre>
<h3 id="pattern-5-mask-sensitive-data">Pattern 5: Mask Sensitive Data</h3>
<pre><code class="language-vbnet">Function MaskString(text As String, Optional maskChar As String = &quot;*&quot;) As String
    MaskString = String(Len(text), maskChar)
End Function</code></pre>
<h3 id="pattern-6-indent-text">Pattern 6: Indent Text</h3>
<pre><code class="language-vbnet">Function IndentText(text As String, level As Integer, _
                    Optional indentSize As Integer = 4) As String
    IndentText = String(level * indentSize, &quot; &quot;) &amp; text
End Function</code></pre>
<h3 id="pattern-7-create-ruler">Pattern 7: Create Ruler</h3>
<pre><code class="language-vbnet">Function CreateRuler(length As Integer) As String
    Dim i As Integer
    Dim ruler As String
    Dim markers As String
    &#x27; Create tick marks every 10 characters
    ruler = &quot;&quot;
    markers = &quot;&quot;
    For i = 1 To length
        If i Mod 10 = 0 Then
            ruler = ruler &amp; &quot;|&quot;
            markers = markers &amp; CStr(i \ 10 Mod 10)
        Else
            ruler = ruler &amp; &quot;.&quot;
            markers = markers &amp; &quot; &quot;
        End If
    Next i
    CreateRuler = markers &amp; vbCrLf &amp; ruler
End Function</code></pre>
<h3 id="pattern-8-fill-to-width">Pattern 8: Fill to Width</h3>
<pre><code class="language-vbnet">Function FillToWidth(text As String, width As Integer, _
                     Optional fillChar As String = &quot; &quot;) As String
    If Len(text) &gt;= width Then
        FillToWidth = Left$(text, width)
    Else
        FillToWidth = text &amp; String(width - Len(text), fillChar)
    End If
End Function</code></pre>
<h3 id="pattern-9-create-loading-animation">Pattern 9: Create Loading Animation</h3>
<pre><code class="language-vbnet">Function LoadingBar(step As Integer, totalSteps As Integer, width As Integer) As String
    Dim filled As Integer
    filled = (step * width) \ totalSteps
    LoadingBar = String(filled, &quot;=&quot;) &amp; &quot;&gt;&quot; &amp; String(width - filled - 1, &quot; &quot;)
End Function</code></pre>
<h3 id="pattern-10-duplicate-character">Pattern 10: Duplicate Character</h3>
<pre><code class="language-vbnet">Function RepeatChar(char As String, count As Integer) As String
    &#x27; Alias for String function with clearer name
    RepeatChar = String(count, char)
End Function</code></pre>
<h2 id="advanced-usage">Advanced Usage</h2>
<h3 id="example-1-text-box-drawer">Example 1: Text Box Drawer</h3>
<pre><code class="language-vbnet">&#x27; Class: TextBoxDrawer
&#x27; Draws ASCII boxes around text
Option Explicit
Private m_Width As Integer
Private m_Padding As Integer
Public Sub Initialize(width As Integer, Optional padding As Integer = 1)
    m_Width = width
    m_Padding = padding
End Sub
Public Function DrawBox(title As String, lines() As String) As String
    Dim result As String
    Dim i As Integer
    Dim maxLen As Integer
    &#x27; Find maximum line length
    maxLen = Len(title)
    For i = LBound(lines) To UBound(lines)
        If Len(lines(i)) &gt; maxLen Then maxLen = Len(lines(i))
    Next i
    &#x27; Adjust width if needed
    If m_Width &lt; maxLen + (m_Padding * 2) + 2 Then
        m_Width = maxLen + (m_Padding * 2) + 2
    End If
    &#x27; Top border
    result = &quot;+&quot; &amp; String(m_Width - 2, &quot;-&quot;) &amp; &quot;+&quot; &amp; vbCrLf
    &#x27; Title (centered)
    If Len(title) &gt; 0 Then
        result = result &amp; &quot;|&quot; &amp; CenterInWidth(title, m_Width - 2) &amp; &quot;|&quot; &amp; vbCrLf
        result = result &amp; &quot;+&quot; &amp; String(m_Width - 2, &quot;-&quot;) &amp; &quot;+&quot; &amp; vbCrLf
    End If
    &#x27; Content lines
    For i = LBound(lines) To UBound(lines)
        result = result &amp; &quot;|&quot; &amp; PadLine(lines(i), m_Width - 2) &amp; &quot;|&quot; &amp; vbCrLf
    Next i
    &#x27; Bottom border
    result = result &amp; &quot;+&quot; &amp; String(m_Width - 2, &quot;-&quot;) &amp; &quot;+&quot;
    DrawBox = result
End Function
Private Function CenterInWidth(text As String, width As Integer) As String
    Dim leftPad As Integer
    Dim rightPad As Integer
    Dim totalPad As Integer
    totalPad = width - Len(text)
    leftPad = totalPad \ 2
    rightPad = totalPad - leftPad
    CenterInWidth = String(leftPad, &quot; &quot;) &amp; text &amp; String(rightPad, &quot; &quot;)
End Function
Private Function PadLine(text As String, width As Integer) As String
    Dim content As String
    content = String(m_Padding, &quot; &quot;) &amp; text
    PadLine = content &amp; String(width - Len(content), &quot; &quot;)
End Function</code></pre>
<h3 id="example-2-progress-bar-generator">Example 2: Progress Bar Generator</h3>
<pre><code class="language-vbnet">&#x27; Class: ProgressBarGenerator
&#x27; Creates customizable progress bars
Option Explicit
Private m_Width As Integer
Private m_FilledChar As String
Private m_EmptyChar As String
Private m_ShowPercent As Boolean
Public Sub Initialize(width As Integer, Optional filledChar As String = &quot;#&quot;, _
                      Optional emptyChar As String = &quot;-&quot;, _
                      Optional showPercent As Boolean = True)
    m_Width = width
    m_FilledChar = filledChar
    m_EmptyChar = emptyChar
    m_ShowPercent = showPercent
End Sub
Public Function Generate(current As Long, total As Long) As String
    Dim percent As Integer
    Dim filled As Integer
    Dim empty As Integer
    Dim bar As String
    If total = 0 Then
        Generate = &quot;[&quot; &amp; String(m_Width, m_EmptyChar) &amp; &quot;]&quot;
        Exit Function
    End If
    percent = CInt((current * 100) / total)
    If percent &gt; 100 Then percent = 100
    filled = (percent * m_Width) \ 100
    empty = m_Width - filled
    bar = &quot;[&quot; &amp; String(filled, m_FilledChar) &amp; String(empty, m_EmptyChar) &amp; &quot;]&quot;
    If m_ShowPercent Then
        bar = bar &amp; &quot; &quot; &amp; Format$(percent, &quot;000&quot;) &amp; &quot;%&quot;
    End If
    Generate = bar
End Function
Public Function GenerateIndeterminate(step As Integer) As String
    &#x27; Animated indeterminate progress bar
    Dim pos As Integer
    Dim blockSize As Integer
    blockSize = 5
    pos = step Mod (m_Width + blockSize)
    If pos &lt; blockSize Then
        GenerateIndeterminate = &quot;[&quot; &amp; String(pos, m_FilledChar) &amp; _
                               String(m_Width - pos, m_EmptyChar) &amp; &quot;]&quot;
    ElseIf pos &lt; m_Width Then
        GenerateIndeterminate = &quot;[&quot; &amp; String(pos - blockSize, m_EmptyChar) &amp; _
                               String(blockSize, m_FilledChar) &amp; _
                               String(m_Width - pos, m_EmptyChar) &amp; &quot;]&quot;
    Else
        GenerateIndeterminate = &quot;[&quot; &amp; String(m_Width - (pos - m_Width), m_EmptyChar) &amp; _
                               String(pos - m_Width, m_FilledChar) &amp; &quot;]&quot;
    End If
End Function</code></pre>
<h3 id="example-3-table-formatter-module">Example 3: Table Formatter Module</h3>
<pre><code class="language-vbnet">&#x27; Module: TableFormatter
&#x27; Creates formatted ASCII tables
Option Explicit
Public Function CreateTable(headers() As String, data() As String, _
                            columnWidths() As Integer) As String
    Dim result As String
    Dim i As Integer
    Dim j As Integer
    Dim row As Integer
    Dim col As Integer
    &#x27; Top border
    result = CreateBorder(columnWidths, True) &amp; vbCrLf
    &#x27; Headers
    result = result &amp; CreateRow(headers, columnWidths) &amp; vbCrLf
    &#x27; Separator
    result = result &amp; CreateBorder(columnWidths, False) &amp; vbCrLf
    &#x27; Data rows
    row = LBound(data, 1)
    Do While row &lt;= UBound(data, 1)
        Dim rowData() As String
        ReDim rowData(LBound(headers) To UBound(headers))
        For col = LBound(headers) To UBound(headers)
            rowData(col) = data(row, col)
        Next col
        result = result &amp; CreateRow(rowData, columnWidths) &amp; vbCrLf
        row = row + 1
    Loop
    &#x27; Bottom border
    result = result &amp; CreateBorder(columnWidths, True)
    CreateTable = result
End Function
Private Function CreateBorder(columnWidths() As Integer, heavy As Boolean) As String
    Dim i As Integer
    Dim result As String
    Dim corner As String
    Dim line As String
    If heavy Then
        corner = &quot;+&quot;
        line = &quot;=&quot;
    Else
        corner = &quot;+&quot;
        line = &quot;-&quot;
    End If
    result = corner
    For i = LBound(columnWidths) To UBound(columnWidths)
        result = result &amp; String(columnWidths(i) + 2, line) &amp; corner
    Next i
    CreateBorder = result
End Function
Private Function CreateRow(cells() As String, columnWidths() As Integer) As String
    Dim i As Integer
    Dim result As String
    Dim cell As String
    result = &quot;|&quot;
    For i = LBound(cells) To UBound(cells)
        cell = &quot; &quot; &amp; cells(i)
        If Len(cell) &lt; columnWidths(i) + 1 Then
            cell = cell &amp; String(columnWidths(i) + 1 - Len(cell), &quot; &quot;)
        End If
        result = result &amp; cell &amp; &quot; |&quot;
    Next i
    CreateRow = result
End Function</code></pre>
<h3 id="example-4-text-padding-utilities">Example 4: Text Padding Utilities</h3>
<pre><code class="language-vbnet">&#x27; Module: TextPaddingUtils
&#x27; Utilities for padding and aligning text
Option Explicit
Public Function PadLeft(text As String, width As Integer, _
                        Optional padChar As String = &quot; &quot;) As String
    If Len(text) &gt;= width Then
        PadLeft = text
    Else
        PadLeft = String(width - Len(text), padChar) &amp; text
    End If
End Function
Public Function PadRight(text As String, width As Integer, _
                         Optional padChar As String = &quot; &quot;) As String
    If Len(text) &gt;= width Then
        PadRight = text
    Else
        PadRight = text &amp; String(width - Len(text), padChar)
    End If
End Function
Public Function PadCenter(text As String, width As Integer, _
                          Optional padChar As String = &quot; &quot;) As String
    Dim totalPad As Integer
    Dim leftPad As Integer
    Dim rightPad As Integer
    If Len(text) &gt;= width Then
        PadCenter = text
        Exit Function
    End If
    totalPad = width - Len(text)
    leftPad = totalPad \ 2
    rightPad = totalPad - leftPad
    PadCenter = String(leftPad, padChar) &amp; text &amp; String(rightPad, padChar)
End Function
Public Function CreateLine(width As Integer, Optional lineChar As String = &quot;-&quot;) As String
    CreateLine = String(width, lineChar)
End Function
Public Function FrameText(text As String, width As Integer, _
                          Optional frameChar As String = &quot;*&quot;) As String
    Dim topBottom As String
    Dim middle As String
    topBottom = String(width, frameChar)
    middle = frameChar &amp; PadCenter(text, width - 2) &amp; frameChar
    FrameText = topBottom &amp; vbCrLf &amp; middle &amp; vbCrLf &amp; topBottom
End Function
Public Function Underline(text As String, Optional underlineChar As String = &quot;-&quot;) As String
    Underline = text &amp; vbCrLf &amp; String(Len(text), underlineChar)
End Function
Public Function NumberedLine(lineNum As Integer, text As String, _
                             totalWidth As Integer) As String
    Dim numStr As String
    numStr = PadLeft(CStr(lineNum), 4) &amp; &quot;: &quot;
    NumberedLine = numStr &amp; text &amp; String(totalWidth - Len(numStr) - Len(text), &quot; &quot;)
End Function</code></pre>
<h2 id="error-handling">Error Handling</h2>
<p>The <code>String</code> function can raise the following errors:
- <strong>Error 5 (Invalid procedure call or argument)</strong>: If <code>number</code> is negative
- <strong>Error 6 (Overflow)</strong>: If <code>number</code> is too large (exceeds memory limits)
- <strong>Error 13 (Type mismatch)</strong>: If <code>character</code> cannot be converted to a valid character
- <strong>Error 5 (Invalid procedure call)</strong>: If <code>character</code> is a numeric value outside 0-255 range</p>
<h2 id="performance-notes">Performance Notes</h2>
<ul>
<li>Very fast and efficient for creating repeating character strings</li>
<li>More efficient than concatenating characters in a loop</li>
<li>Memory allocation is done once for the entire string</li>
<li>For very large strings (millions of characters), consider memory constraints</li>
<li>Slightly faster than equivalent loop-based approaches</li>
</ul>
<h2 id="best-practices">Best Practices</h2>
<ol>
<li><strong>Use descriptive variable names</strong> when storing String results (e.g., <code>separator</code>, <code>padding</code>)</li>
<li><strong>Validate number parameter</strong> to ensure it's non-negative before calling</li>
<li><strong>Use named constants</strong> for common character codes (e.g., <code>Const ASTERISK = 42</code>)</li>
<li><strong>Prefer string literals</strong> over character codes for clarity (e.g., <code>String(5, "*")</code> vs <code>String(5, 42)</code>)</li>
<li><strong>Consider Space function</strong> for creating space-filled strings (<code>Space(n)</code> vs <code>String(n, " ")</code>)</li>
<li><strong>Cache repeated strings</strong> if used multiple times in a function</li>
<li><strong>Check string length</strong> before padding operations to avoid overflow</li>
<li><strong>Use for visual elements</strong> like separators, borders, and progress indicators</li>
<li><strong>Document character choice</strong> when using character codes instead of string literals</li>
<li><strong>Test with edge cases</strong> like <code>number = 0</code> and very large values</li>
</ol>
<h2 id="comparison-table">Comparison Table</h2>
<table>
<thead>
<tr>
<th>Function</th>
<th>Purpose</th>
<th>Example</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>String</code></td>
<td>Repeat character</td>
<td><code>String(5, "*")</code></td>
<td><code>"*****"</code></td>
</tr>
<tr>
<td><code>Space</code></td>
<td>Repeat space</td>
<td><code>Space(5)</code></td>
<td><code>"     "</code></td>
</tr>
<tr>
<td><code>String$</code></td>
<td>Type-declared variant</td>
<td><code>String$(5, 42)</code></td>
<td><code>"*****"</code></td>
</tr>
</tbody>
</table>
<h2 id="platform-notes">Platform Notes</h2>
<ul>
<li>Available in VB6 and VBA</li>
<li>Not available in <code>VBScript</code> (use custom function instead)</li>
<li><code>String$</code> variant returns String type directly (slightly faster)</li>
<li>Behavior consistent across all platforms</li>
<li>Character codes follow ANSI/ASCII standard (0-255)</li>
<li>Maximum string length limited by available memory</li>
</ul>
<h2 id="limitations">Limitations</h2>
<ul>
<li>Cannot create strings with multiple different repeating characters in one call</li>
<li>Character code must be 0-255 (no Unicode character codes)</li>
<li>If <code>character</code> is a string, only first character is used (no validation of length)</li>
<li>Very large <code>number</code> values can cause out-of-memory errors</li>
<li>No built-in way to create alternating patterns</li>
<li>Cannot specify different characters at different positions</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>