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
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
<!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 - loadresstring - Resources">
    <title>loadresstring - Resources - 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/resources/index.html">Resources</a> / loadresstring</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="loadresstring-function">LoadResString Function</h1>
<p>Returns a string from a resource (.res) file.</p>
<h2 id="syntax">Syntax</h2>
<pre><code class="language-vbnet">LoadResString(index)</code></pre>
<h2 id="parameters">Parameters</h2>
<ul>
<li><code>index</code> (Required): Integer identifying the string resource</li>
<li>Must be a numeric ID (string names not supported for string resources)</li>
<li>Must match the ID used when the resource was compiled</li>
<li>Typically ranges from 1 to 65535</li>
</ul>
<h2 id="return-value">Return Value</h2>
<p>Returns a String:
- String containing the text from the resource file
- Empty string ("") if resource not found (in some VB versions)
- May raise error 32813 if resource not found
- Preserves all formatting including line breaks
- Unicode strings supported in VB6</p>
<h2 id="remarks">Remarks</h2>
<p>The <code>LoadResString</code> function loads text from embedded resources:
- Loads strings from compiled resource (.res) files
- Resource file must be linked to project at compile time
- Primary method for internationalization (i18n) in VB6
- Allows localizing applications without code changes
- Strings can be translated by replacing resource file
- No external text files needed at runtime
- Embedded in compiled EXE/DLL
- Only one resource file per project
- Resource file added via Project &gt; Add File
- Resource files created with Resource Editor or RC.EXE
- Index must be numeric (string names not supported)
- Common for error messages, prompts, labels
- Supports Unicode in VB6
- Error 32813: "Resource not found" if ID doesn't exist
- Error 48: "Error loading from file" if resource file corrupt
- More maintainable than hardcoded strings
- Easier to update text without recompiling code
- Standard practice for multi-language applications
- Can store long text passages
- Supports special characters and formatting</p>
<h2 id="typical-uses">Typical Uses</h2>
<ol>
<li><strong>Load Error Message</strong></li>
</ol>
<pre><code class="language-vbnet">   MsgBox LoadResString(1001), vbCritical
   ```
2. **Load Form Caption**
   ```vb
   Me.Caption = LoadResString(2001)
   ```
3. **Load Label Text**
   ```vb
   lblWelcome.Caption = LoadResString(3001)
   ```
4. **Load Menu Caption**
   ```vb
   mnuFile.Caption = LoadResString(4001)
   ```
5. **Load Button Caption**
   ```vb
   cmdOK.Caption = LoadResString(5001)
   ```
6. **Load `MessageBox` Text**
   ```vb
   MsgBox LoadResString(6001), vbInformation
   ```
7. **Load `StatusBar` Text**
   ```vb
   StatusBar1.SimpleText = LoadResString(7001)
   ```
8. **Load `ToolTip` Text**
   ```vb
   cmdSave.ToolTipText = LoadResString(8001)
   ```
## Basic Examples
### Example 1: Loading Messages</code></pre>
<p>vb
' Load various UI strings from resources
Me.Caption = LoadResString(1001)          ' "My Application"
lblTitle.Caption = LoadResString(1002)    ' "Welcome!"
cmdOK.Caption = LoadResString(1003)       ' "OK"
cmdCancel.Caption = LoadResString(1004)   ' "Cancel"</p>
<pre><code>### Example 2: Error Messages</code></pre>
<p>vb
' Use resource strings for error messages
If Not fileExists Then
    MsgBox LoadResString(2001), vbCritical  ' "File not found"
End If
If accessDenied Then
    MsgBox LoadResString(2002), vbCritical  ' "Access denied"
End If</p>
<pre><code>### Example 3: Error Handling</code></pre>
<p>vb
On Error Resume Next
Dim msg As String
msg = LoadResString(9999)
If Err.Number = 32813 Then
    msg = "String resource not found!"
    Err.Clear
End If
MsgBox msg</p>
<pre><code>### Example 4: Form Initialization</code></pre>
<p>vb
Private Sub Form_Load()
    ' Load all UI strings from resources
    Me.Caption = LoadResString(1001)
    lblName.Caption = LoadResString(1002)
    lblAddress.Caption = LoadResString(1003)
    cmdSave.Caption = LoadResString(1004)
    cmdCancel.Caption = LoadResString(1005)
End Sub</p>
<pre><code>## Common Patterns
### Pattern 1: `SafeLoadResString`</code></pre>
<p>vb
Function SafeLoadResString(ByVal resID As Integer, _
                           Optional ByVal defaultText As String = "") As String
    On Error Resume Next
    SafeLoadResString = LoadResString(resID)
    If Err.Number &lt;&gt; 0 Then
        SafeLoadResString = defaultText
        Err.Clear
    End If
End Function</p>
<pre><code>### Pattern 2: `LoadFormStrings`</code></pre>
<p>vb
Sub LoadFormStrings(frm As Form, ByVal baseID As Integer)
    Dim ctrl As Control
    Dim id As Integer
    On Error Resume Next
    frm.Caption = LoadResString(baseID)
    id = baseID + 1
    For Each ctrl In frm.Controls
        If TypeOf ctrl Is Label Or TypeOf ctrl Is CommandButton Then
            ctrl.Caption = LoadResString(id)
            id = id + 1
        End If
    Next ctrl
End Sub</p>
<pre><code>### Pattern 3: `FormatResString`</code></pre>
<p>vb
Function FormatResString(ByVal resID As Integer, _
                         ParamArray args()) As String
    Dim template As String
    Dim i As Long
    template = LoadResString(resID)
    For i = LBound(args) To UBound(args)
        template = Replace(template, "{" &amp; i &amp; "}", CStr(args(i)))
    Next i
    FormatResString = template
End Function</p>
<pre><code>### Pattern 4: `GetErrorMessage`</code></pre>
<p>vb
Function GetErrorMessage(ByVal errorCode As Long) As String
    Const BASE_ERROR_ID = 10000
    On Error Resume Next
    GetErrorMessage = LoadResString(BASE_ERROR_ID + errorCode)
    If Err.Number &lt;&gt; 0 Then
        GetErrorMessage = "Unknown error: " &amp; errorCode
        Err.Clear
    End If
End Function</p>
<pre><code>### Pattern 5: `LoadMenuStrings`</code></pre>
<p>vb
Sub LoadMenuStrings()
    Const MENU_BASE = 4000
    mnuFile.Caption = LoadResString(MENU_BASE + 1)      ' "&amp;File"
    mnuFileNew.Caption = LoadResString(MENU_BASE + 2)   ' "&amp;New"
    mnuFileOpen.Caption = LoadResString(MENU_BASE + 3)  ' "&amp;Open"
    mnuFileSave.Caption = LoadResString(MENU_BASE + 4)  ' "&amp;Save"
    mnuFileExit.Caption = LoadResString(MENU_BASE + 5)  ' "E&amp;xit"
End Sub</p>
<pre><code>### Pattern 6: `CachedResString`</code></pre>
<p>vb
Dim resStringCache As New Collection
Function CachedLoadResString(ByVal resID As Integer) As String
    Dim key As String
    On Error Resume Next
    key = "RES_" &amp; resID
    CachedLoadResString = resStringCache(key)
    If Err.Number &lt;&gt; 0 Then
        Err.Clear
        CachedLoadResString = LoadResString(resID)
        resStringCache.Add CachedLoadResString, key
    End If
End Function</p>
<pre><code>### Pattern 7: `ResStringExists`</code></pre>
<p>vb
Function ResStringExists(ByVal resID As Integer) As Boolean
    On Error Resume Next
    Dim s As String
    s = LoadResString(resID)
    ResStringExists = (Err.Number = 0)
    Err.Clear
End Function</p>
<pre><code>### Pattern 8: `LoadResStringArray`</code></pre>
<p>vb
Function LoadResStringArray(ByVal startID As Integer, _
                            ByVal count As Integer) As String()
    Dim result() As String
    Dim i As Integer
    ReDim result(0 To count - 1)
    On Error Resume Next
    For i = 0 To count - 1
        result(i) = LoadResString(startID + i)
        If Err.Number &lt;&gt; 0 Then
            result(i) = ""
            Err.Clear
        End If
    Next i
    LoadResStringArray = result
End Function</p>
<pre><code>### Pattern 9: `ShowResMessage`</code></pre>
<p>vb
Sub ShowResMessage(ByVal resID As Integer, _
                   Optional ByVal icon As VbMsgBoxStyle = vbInformation)
    On Error Resume Next
    Dim msg As String
    msg = LoadResString(resID)
    If Err.Number = 0 Then
        MsgBox msg, icon
    Else
        MsgBox "Message resource " &amp; resID &amp; " not found", vbCritical
        Err.Clear
    End If
End Sub</p>
<pre><code>### Pattern 10: `MultiLineResString`</code></pre>
<p>vb
Function MultiLineResString(ByVal resID As Integer) As String
    Dim text As String
    text = LoadResString(resID)
    ' Resource strings preserve line breaks
    MultiLineResString = text
End Function</p>
<pre><code>## Advanced Examples
### Example 1: Localization Manager</code></pre>
<p>vb
' Class: LocalizationManager
Private m_cache As Collection
Private m_languageID As Integer
Private Sub Class_Initialize()
    Set m_cache = New Collection
    m_languageID = 1033 ' Default to English (US)
End Sub
Public Property Let LanguageID(ByVal newLanguage As Integer)
    m_languageID = newLanguage
    ClearCache
End Property
Public Function GetString(ByVal baseID As Integer) As String
    Dim resID As Integer
    Dim key As String
    On Error Resume Next
    resID = baseID + m_languageID
    key = "STR_" &amp; resID
    GetString = m_cache(key)
    If Err.Number &lt;&gt; 0 Then
        Err.Clear
        GetString = LoadResString(resID)
        If Err.Number = 0 Then
            m_cache.Add GetString, key
        Else
            ' Fallback to default language
            GetString = LoadResString(baseID + 1033)
            Err.Clear
        End If
    End If
End Function
Public Sub LocalizeForm(frm As Form)
    Dim ctrl As Control
    On Error Resume Next
    ' Load form caption
    frm.Caption = GetString(GetFormBaseID(frm))
    ' Load control captions
    For Each ctrl In frm.Controls
        If HasCaption(ctrl) Then
            ctrl.Caption = GetString(GetControlID(ctrl))
        End If
    Next ctrl
End Sub
Private Sub ClearCache()
    Set m_cache = New Collection
End Sub
Private Function HasCaption(ctrl As Control) As Boolean
    HasCaption = TypeOf ctrl Is Label Or _
                 TypeOf ctrl Is CommandButton Or _
                 TypeOf ctrl Is CheckBox Or _
                 TypeOf ctrl Is OptionButton
End Function
Private Sub Class_Terminate()
    Set m_cache = Nothing
End Sub</p>
<pre><code>### Example 2: Error Message System</code></pre>
<p>vb
' Module: ErrorMessages
Private Const ERR_BASE = 20000
Public Enum AppError
    errFileNotFound = 1
    errAccessDenied = 2
    errInvalidFormat = 3
    errNetworkError = 4
    errDatabaseError = 5
End Enum
Public Sub ShowError(ByVal errorType As AppError, _
                     Optional ByVal additionalInfo As String = "")
    Dim msg As String
    On Error Resume Next
    msg = LoadResString(ERR_BASE + errorType)
    If Err.Number &lt;&gt; 0 Then
        msg = "Unknown error occurred"
        Err.Clear
    End If
    If Len(additionalInfo) &gt; 0 Then
        msg = msg &amp; vbCrLf &amp; vbCrLf &amp; additionalInfo
    End If
    MsgBox msg, vbCritical, LoadResString(ERR_BASE)
End Sub
Public Function GetErrorText(ByVal errorType As AppError) As String
    On Error Resume Next
    GetErrorText = LoadResString(ERR_BASE + errorType)
    If Err.Number &lt;&gt; 0 Then
        GetErrorText = "Unknown error"
        Err.Clear
    End If
End Function</p>
<pre><code>### Example 3: Multi-Language Application</code></pre>
<p>vb
' Form with language selection
Public Enum Language
    langEnglish = 0
    langSpanish = 1000
    langFrench = 2000
    langGerman = 3000
End Enum
Private currentLanguage As Language
Private Sub Form_Load()
    ' Default to English
    currentLanguage = langEnglish
    LoadLanguage
End Sub
Private Sub cboLanguage_Click()
    Select Case cboLanguage.ListIndex
        Case 0: currentLanguage = langEnglish
        Case 1: currentLanguage = langSpanish
        Case 2: currentLanguage = langFrench
        Case 3: currentLanguage = langGerman
    End Select
    LoadLanguage
End Sub
Private Sub LoadLanguage()
    Dim baseID As Integer
    baseID = 10000 + currentLanguage
    On Error Resume Next
    Me.Caption = LoadResString(baseID + 1)
    lblWelcome.Caption = LoadResString(baseID + 2)
    lblInstructions.Caption = LoadResString(baseID + 3)
    cmdStart.Caption = LoadResString(baseID + 4)
    cmdExit.Caption = LoadResString(baseID + 5)
    ' Update menu
    mnuFile.Caption = LoadResString(baseID + 10)
    mnuHelp.Caption = LoadResString(baseID + 11)
End Sub</p>
<pre><code>### Example 4: String Template System</code></pre>
<p>vb
' Module: StringTemplates
Private Const TEMPLATE_BASE = 30000
Public Function GetFormattedString(ByVal templateID As Integer, _
                                   ParamArray values()) As String
    Dim template As String
    Dim result As String
    Dim i As Long
    On Error Resume Next
    template = LoadResString(TEMPLATE_BASE + templateID)
    If Err.Number &lt;&gt; 0 Then
        GetFormattedString = ""
        Err.Clear
        Exit Function
    End If
    result = template
    For i = LBound(values) To UBound(values)
        result = Replace(result, "{" &amp; i &amp; "}", CStr(values(i)))
    Next i
    GetFormattedString = result
End Function
Public Function GetWelcomeMessage(ByVal userName As String) As String
    ' Template: "Welcome, {0}! You have {1} new messages."
    GetWelcomeMessage = GetFormattedString(1, userName, GetMessageCount())
End Function
Public Function GetSaveConfirmation(ByVal filename As String) As String
    ' Template: "Do you want to save changes to {0}?"
    GetSaveConfirmation = GetFormattedString(2, filename)
End Function
Private Function GetMessageCount() As Long
    ' Implementation would return actual message count
    GetMessageCount = 5
End Function</p>
<pre><code>## Error Handling</code></pre>
<p>vb
' Error 32813: Resource not found
On Error Resume Next
Dim msg As String
msg = LoadResString(9999)
If Err.Number = 32813 Then
    MsgBox "String resource not found!"
End If
' Error 48: Error loading from file
msg = LoadResString(1001)
If Err.Number = 48 Then
    MsgBox "Resource file is corrupt or missing!"
End If
' Safe loading pattern
Function TryLoadResString(ByVal resID As Integer, _
                          ByRef outString As String) As Boolean
    On Error Resume Next
    outString = LoadResString(resID)
    TryLoadResString = (Err.Number = 0)
    If Err.Number &lt;&gt; 0 Then
        outString = ""
    End If
    Err.Clear
End Function</p>
<pre><code>## Performance Considerations
- **Fast Access**: Strings embedded in EXE (very fast loading)
- **No File I/O**: No disk access required
- **No Caching**: Each call loads fresh copy (implement caching if needed)
- **Memory Efficient**: Strings only loaded when accessed
- **Cache Strategy**: For frequently used strings, cache in Collection or array
- **Startup Time**: Loading many strings at startup may slow `Form_Load`
## Best Practices
1. **Use constants** for string IDs for maintainability
2. **Group by category** using ID ranges (1000s for errors, 2000s for menus, etc.)
3. **Cache frequently used strings** to improve performance
4. **Always handle errors** - resource might not exist
5. **Document string IDs** in code or separate file
6. **Use templates** with placeholders for dynamic content
7. **Organize by language** using ID offsets (English: 0, Spanish: +1000, etc.)
8. **Test all languages** before deployment
9. **Provide fallbacks** for missing strings
10. **Keep strings updated** in sync with code changes
## Comparison with Related Functions
| Function | Purpose | Return Type | Data Type |
|----------|---------|-------------|-----------|
| **`LoadResString`** | Load string from resources | String | Text strings |
| **`LoadResPicture`** | Load image from resources | `StdPicture` | Images |
| **`LoadResData`** | Load binary data from resources | Byte array | Binary data |
| **`LoadString`** (API) | Windows API alternative | String | Text strings |
## `LoadResString` vs Hardcoded Strings</code></pre>
<p>vb
' Hardcoded - difficult to localize
MsgBox "File not found", vbCritical
' Resource string - easy to localize
MsgBox LoadResString(1001), vbCritical</p>
<pre><code>**Advantages of `LoadResString`:**
- Easy localization (just replace .res file)
- Centralized string management
- No code changes needed for translations
- Consistent messaging across application
## String ID Organization</code></pre>
<p>vb
' Recommended ID ranges
Const STR_APP_BASE = 1000         ' Application strings
Const STR_ERROR_BASE = 2000       ' Error messages
Const STR_MENU_BASE = 3000        ' Menu items
Const STR_DIALOG_BASE = 4000      ' Dialog messages
Const STR_STATUS_BASE = 5000      ' Status messages
Const STR_HELP_BASE = 6000        ' Help text
' Language offsets
Const LANG_ENGLISH = 0
Const LANG_SPANISH = 10000
Const LANG_FRENCH = 20000
```</p>
<h2 id="platform-notes">Platform Notes</h2>
<ul>
<li>Available in VB6 (not in early VB versions)</li>
<li>Requires resource file (.res) linked to project</li>
<li>Resource file created with Resource Editor or RC.EXE</li>
<li>Only one resource file per project</li>
<li>Resources embedded in compiled EXE/DLL</li>
<li>Supports Unicode strings in VB6</li>
<li>Index must be Integer (1-65535)</li>
<li>String names not supported (numeric IDs only)</li>
<li>Standard method for internationalization</li>
<li>Preserves formatting including line breaks</li>
</ul>
<h2 id="limitations">Limitations</h2>
<ul>
<li><strong>One Resource File</strong>: Only one .res file per project</li>
<li><strong>Numeric IDs Only</strong>: Cannot use string names for string resources</li>
<li><strong>Compile Time</strong>: Must recompile to update strings</li>
<li><strong>No Modification</strong>: Cannot modify resources at runtime</li>
<li><strong>Limited Editor</strong>: VB6 Resource Editor is basic</li>
<li><strong>ID Range</strong>: Limited to 1-65535</li>
<li><strong>No Encryption</strong>: Strings easily extractable from EXE</li>
<li><strong>No Formatting</strong>: No printf-style formatting (must implement manually)</li>
<li><strong>No Pluralization</strong>: No built-in plural form handling</li>
<li><strong>No Context</strong>: All strings in flat namespace</li>
</ul>
<h2 id="related-functions">Related Functions</h2>
<ul>
<li><code>LoadResPicture</code>: Load picture from resource file</li>
<li><code>LoadResData</code>: Load binary data from resource file</li>
<li><code>LoadPicture</code>: Load picture from external file</li>
<li><code>Format</code>: Format strings with values</li>
<li><code>Replace</code>: Replace placeholders in strings</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 Resources</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>