<!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 > 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 <> 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, "{" & i & "}", 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 <> 0 Then
GetErrorMessage = "Unknown error: " & 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) ' "&File"
mnuFileNew.Caption = LoadResString(MENU_BASE + 2) ' "&New"
mnuFileOpen.Caption = LoadResString(MENU_BASE + 3) ' "&Open"
mnuFileSave.Caption = LoadResString(MENU_BASE + 4) ' "&Save"
mnuFileExit.Caption = LoadResString(MENU_BASE + 5) ' "E&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_" & resID
CachedLoadResString = resStringCache(key)
If Err.Number <> 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 <> 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 " & resID & " 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_" & resID
GetString = m_cache(key)
If Err.Number <> 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 <> 0 Then
msg = "Unknown error occurred"
Err.Clear
End If
If Len(additionalInfo) > 0 Then
msg = msg & vbCrLf & vbCrLf & 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 <> 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 <> 0 Then
GetFormattedString = ""
Err.Clear
Exit Function
End If
result = template
For i = LBound(values) To UBound(values)
result = Replace(result, "{" & i & "}", 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 <> 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>© 2024-2026 VB6Parse Contributors. Licensed under the MIT License.</p>
</div>
</footer>
</body>
</html>