vb6parse 1.0.1

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
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
<!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 - getallsettings - Environment">
    <title>getallsettings - Environment - 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/environment/index.html">Environment</a> / getallsettings</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>GetAllSettings Function
Returns a list of key settings and their respective values (originally created with <code>SaveSetting</code>) from an application's entry in the Windows registry.</p>
<h1 id="syntax">Syntax</h1>
<pre><code class="language-vbnet">GetAllSettings(appname, section)</code></pre>
<h1 id="parameters">Parameters</h1>
<ul>
<li><code>appname</code> - Required. String expression containing the name of the application or project whose key settings are requested.</li>
<li><code>section</code> - Required. String expression containing the name of the section whose key settings are requested.</li>
</ul>
<h1 id="return-value">Return Value</h1>
<p>Returns a <code>Variant</code> containing a two-dimensional array of strings. The first dimension contains the key names, and the second dimension contains the corresponding values.</p>
<h1 id="remarks">Remarks</h1>
<ul>
<li><code>GetAllSettings</code> returns an uninitialized <code>Variant</code> if either <code>appname</code> or <code>section</code> does not exist.</li>
<li>The returned array is zero-based with two columns: column 0 contains key names, column 1 contains values.</li>
<li>Works with the Windows registry (<code>HKEY_CURRENT_USER\Software\VB and VBA Program Settings\appname\section</code>).</li>
<li>On Windows, settings are stored in: <code>HKEY_CURRENT_USER\Software\VB and VBA Program Settings\appname\section</code>.</li>
<li>Use <code>SaveSetting</code> to write values that <code>GetAllSettings</code> can retrieve.</li>
<li>Use <code>GetSetting</code> to retrieve individual settings.</li>
<li>Use <code>DeleteSetting</code> to remove settings from the registry.</li>
<li><code>GetAllSettings</code> is Windows-specific and relies on the registry.</li>
</ul>
<h1 id="typical-uses">Typical Uses</h1>
<ul>
<li>Loading application configuration settings</li>
<li>Retrieving user preferences</li>
<li>Reading saved window positions and sizes</li>
<li>Loading multiple related settings at once</li>
<li>Migrating settings between versions</li>
<li>Exporting application configuration</li>
</ul>
<h1 id="basic-usage-examples">Basic Usage Examples</h1>
<pre><code class="language-vbnet">&#x27; Retrieve all settings for a section
Dim allSettings As Variant
Dim i As Long
allSettings = GetAllSettings(&quot;MyApp&quot;, &quot;Preferences&quot;)
If IsEmpty(allSettings) Then
    Debug.Print &quot;No settings found&quot;
Else
    For i = LBound(allSettings, 1) To UBound(allSettings, 1)
        Debug.Print allSettings(i, 0) &amp; &quot; = &quot; &amp; allSettings(i, 1)
    Next i
End If
&#x27; Check if settings exist
Dim settings As Variant
settings = GetAllSettings(&quot;MyApp&quot;, &quot;WindowPosition&quot;)
If Not IsEmpty(settings) Then
    &#x27; Settings exist, process them
    MsgBox &quot;Found &quot; &amp; (UBound(settings, 1) + 1) &amp; &quot; settings&quot;
End If
&#x27; Load and apply settings
Dim appSettings As Variant
appSettings = GetAllSettings(&quot;MyApp&quot;, &quot;Options&quot;)
If Not IsEmpty(appSettings) Then
    Dim j As Long
    For j = 0 To UBound(appSettings, 1)
        Select Case appSettings(j, 0)
            Case &quot;Theme&quot;
                ApplyTheme appSettings(j, 1)
            Case &quot;Language&quot;
                SetLanguage appSettings(j, 1)
        End Select
    Next j
End If</code></pre>
<h1 id="common-patterns">Common Patterns</h1>
<h2 id="1-load-all-application-settings">1. Load All Application Settings</h2>
<pre><code class="language-vbnet">Sub LoadApplicationSettings()
    Dim settings As Variant
    Dim i As Long
    settings = GetAllSettings(&quot;MyApp&quot;, &quot;General&quot;)
    If IsEmpty(settings) Then
        &#x27; No settings found, use defaults
        SetDefaultSettings
    Else
        For i = LBound(settings, 1) To UBound(settings, 1)
            ProcessSetting settings(i, 0), settings(i, 1)
        Next i
    End If
End Sub
Sub ProcessSetting(keyName As String, value As String)
    Select Case keyName
        Case &quot;AutoSave&quot;
            chkAutoSave.Value = IIf(value = &quot;True&quot;, 1, 0)
        Case &quot;SaveInterval&quot;
            txtInterval.Text = value
        Case &quot;BackupEnabled&quot;
            chkBackup.Value = IIf(value = &quot;True&quot;, 1, 0)
    End Select
End Sub</code></pre>
<h2 id="2-restore-window-position">2. Restore Window Position</h2>
<pre><code class="language-vbnet">Sub RestoreWindowPosition(formName As Form)
    Dim settings As Variant
    Dim i As Long
    settings = GetAllSettings(App.Title, &quot;WindowPos&quot;)
    If Not IsEmpty(settings) Then
        For i = LBound(settings, 1) To UBound(settings, 1)
            Select Case settings(i, 0)
                Case &quot;Left&quot;
                    formName.Left = CLng(settings(i, 1))
                Case &quot;Top&quot;
                    formName.Top = CLng(settings(i, 1))
                Case &quot;Width&quot;
                    formName.Width = CLng(settings(i, 1))
                Case &quot;Height&quot;
                    formName.Height = CLng(settings(i, 1))
                Case &quot;WindowState&quot;
                    formName.WindowState = CInt(settings(i, 1))
            End Select
        Next i
    End If
End Sub</code></pre>
<h2 id="3-load-user-preferences">3. Load User Preferences</h2>
<pre><code class="language-vbnet">Function LoadUserPreferences() As Collection
    Dim settings As Variant
    Dim prefs As New Collection
    Dim i As Long
    settings = GetAllSettings(App.Title, &quot;UserPreferences&quot;)
    If Not IsEmpty(settings) Then
        For i = LBound(settings, 1) To UBound(settings, 1)
            prefs.Add settings(i, 1), settings(i, 0)
        Next i
    End If
    Set LoadUserPreferences = prefs
End Function
&#x27; Usage
Sub ApplyUserPreferences()
    Dim prefs As Collection
    Set prefs = LoadUserPreferences()
    If prefs.Count &gt; 0 Then
        On Error Resume Next
        txtFontSize.Text = prefs(&quot;FontSize&quot;)
        cboTheme.Text = prefs(&quot;Theme&quot;)
        chkShowToolbar.Value = IIf(prefs(&quot;ShowToolbar&quot;) = &quot;True&quot;, 1, 0)
        On Error GoTo 0
    End If
End Sub</code></pre>
<h2 id="4-export-settings-to-file">4. Export Settings to File</h2>
<pre><code class="language-vbnet">Sub ExportSettingsToFile(filename As String)
    Dim settings As Variant
    Dim fileNum As Integer
    Dim i As Long
    settings = GetAllSettings(App.Title, &quot;Settings&quot;)
    If IsEmpty(settings) Then
        MsgBox &quot;No settings to export&quot;
        Exit Sub
    End If
    fileNum = FreeFile
    Open filename For Output As #fileNum
    Print #fileNum, &quot;[Settings]&quot;
    For i = LBound(settings, 1) To UBound(settings, 1)
        Print #fileNum, settings(i, 0) &amp; &quot;=&quot; &amp; settings(i, 1)
    Next i
    Close #fileNum
    MsgBox &quot;Settings exported successfully&quot;
End Sub</code></pre>
<h2 id="5-display-settings-in-listbox">5. Display Settings in <code>ListBox</code></h2>
<pre><code class="language-vbnet">Sub PopulateSettingsList(lst As ListBox)
    Dim settings As Variant
    Dim i As Long
    lst.Clear
    settings = GetAllSettings(App.Title, &quot;Configuration&quot;)
    If IsEmpty(settings) Then
        lst.AddItem &quot;(No settings found)&quot;
    Else
        For i = LBound(settings, 1) To UBound(settings, 1)
            lst.AddItem settings(i, 0) &amp; &quot; = &quot; &amp; settings(i, 1)
        Next i
    End If
End Sub</code></pre>
<h2 id="6-validate-settings">6. Validate Settings</h2>
<pre><code class="language-vbnet">Function ValidateSettings(appName As String, section As String) As Boolean
    Dim settings As Variant
    Dim i As Long
    Dim isValid As Boolean
    settings = GetAllSettings(appName, section)
    If IsEmpty(settings) Then
        ValidateSettings = False
        Exit Function
    End If
    isValid = True
    For i = LBound(settings, 1) To UBound(settings, 1)
        &#x27; Validate each setting
        If Not IsValidSetting(settings(i, 0), settings(i, 1)) Then
            Debug.Print &quot;Invalid setting: &quot; &amp; settings(i, 0)
            isValid = False
        End If
    Next i
    ValidateSettings = isValid
End Function
Function IsValidSetting(keyName As String, value As String) As Boolean
    &#x27; Implement validation logic
    IsValidSetting = True
    Select Case keyName
        Case &quot;Port&quot;
            IsValidSetting = IsNumeric(value) And CLng(value) &gt; 0 And CLng(value) &lt; 65536
        Case &quot;Timeout&quot;
            IsValidSetting = IsNumeric(value) And CLng(value) &gt; 0
        Case &quot;Enabled&quot;
            IsValidSetting = (value = &quot;True&quot; Or value = &quot;False&quot;)
    End Select
End Function</code></pre>
<h2 id="7-compare-settings-between-sections">7. Compare Settings Between Sections</h2>
<pre><code class="language-vbnet">Sub CompareSettings(section1 As String, section2 As String)
    Dim settings1 As Variant
    Dim settings2 As Variant
    Dim i As Long
    settings1 = GetAllSettings(App.Title, section1)
    settings2 = GetAllSettings(App.Title, section2)
    Debug.Print &quot;Comparing &quot; &amp; section1 &amp; &quot; vs &quot; &amp; section2
    Debug.Print String(50, &quot;=&quot;)
    If IsEmpty(settings1) Then
        Debug.Print section1 &amp; &quot; has no settings&quot;
    ElseIf IsEmpty(settings2) Then
        Debug.Print section2 &amp; &quot; has no settings&quot;
    Else
        For i = LBound(settings1, 1) To UBound(settings1, 1)
            Debug.Print section1 &amp; &quot;.&quot; &amp; settings1(i, 0) &amp; &quot; = &quot; &amp; settings1(i, 1)
        Next i
        Debug.Print &quot;&quot;
        For i = LBound(settings2, 1) To UBound(settings2, 1)
            Debug.Print section2 &amp; &quot;.&quot; &amp; settings2(i, 0) &amp; &quot; = &quot; &amp; settings2(i, 1)
        Next i
    End If
End Sub</code></pre>
<h2 id="8-migrate-settings-to-new-version">8. Migrate Settings to New Version</h2>
<pre><code class="language-vbnet">Sub MigrateSettings(oldSection As String, newSection As String)
    Dim settings As Variant
    Dim i As Long
    &#x27; Get all settings from old section
    settings = GetAllSettings(App.Title, oldSection)
    If IsEmpty(settings) Then
        Debug.Print &quot;No settings to migrate&quot;
        Exit Sub
    End If
    &#x27; Save to new section
    For i = LBound(settings, 1) To UBound(settings, 1)
        SaveSetting App.Title, newSection, settings(i, 0), settings(i, 1)
    Next i
    Debug.Print &quot;Migrated &quot; &amp; (UBound(settings, 1) + 1) &amp; &quot; settings&quot;
End Sub</code></pre>
<h2 id="9-create-settings-dictionary">9. Create Settings Dictionary</h2>
<pre><code class="language-vbnet">Function GetSettingsDictionary() As Object
    Dim settings As Variant
    Dim dict As Object
    Dim i As Long
    Set dict = CreateObject(&quot;Scripting.Dictionary&quot;)
    settings = GetAllSettings(App.Title, &quot;Config&quot;)
    If Not IsEmpty(settings) Then
        For i = LBound(settings, 1) To UBound(settings, 1)
            dict.Add settings(i, 0), settings(i, 1)
        Next i
    End If
    Set GetSettingsDictionary = dict
End Function
&#x27; Usage
Sub UseSettingsDictionary()
    Dim settings As Object
    Set settings = GetSettingsDictionary()
    If settings.Exists(&quot;ServerURL&quot;) Then
        Debug.Print &quot;Server: &quot; &amp; settings(&quot;ServerURL&quot;)
    End If
End Sub</code></pre>
<h2 id="10-bulk-settings-editor">10. Bulk Settings Editor</h2>
<pre><code class="language-vbnet">Sub EditAllSettings(appName As String, section As String)
    Dim settings As Variant
    Dim i As Long
    Dim newValue As String
    settings = GetAllSettings(appName, section)
    If IsEmpty(settings) Then
        MsgBox &quot;No settings found&quot;
        Exit Sub
    End If
    For i = LBound(settings, 1) To UBound(settings, 1)
        newValue = InputBox(&quot;Enter new value for: &quot; &amp; settings(i, 0), _
                           &quot;Edit Setting&quot;, settings(i, 1))
        If newValue &lt;&gt; &quot;&quot; Then
            SaveSetting appName, section, settings(i, 0), newValue
        End If
    Next i
End Sub</code></pre>
<h1 id="advanced-usage">Advanced Usage</h1>
<h2 id="1-settings-manager-class">1. Settings Manager Class</h2>
<pre><code class="language-vbnet">&#x27; Class: SettingsManager
Private m_AppName As String
Private m_Section As String
Private m_Settings As Variant
Public Sub Initialize(appName As String, section As String)
    m_AppName = appName
    m_Section = section
    RefreshSettings
End Sub
Public Sub RefreshSettings()
    m_Settings = GetAllSettings(m_AppName, m_Section)
End Sub
Public Function GetValue(keyName As String, _
                         Optional defaultValue As String = &quot;&quot;) As String
    Dim i As Long
    If IsEmpty(m_Settings) Then
        GetValue = defaultValue
        Exit Function
    End If
    For i = LBound(m_Settings, 1) To UBound(m_Settings, 1)
        If m_Settings(i, 0) = keyName Then
            GetValue = m_Settings(i, 1)
            Exit Function
        End If
    Next i
    GetValue = defaultValue
End Function
Public Function SettingExists(keyName As String) As Boolean
    Dim i As Long
    If IsEmpty(m_Settings) Then
        SettingExists = False
        Exit Function
    End If
    For i = LBound(m_Settings, 1) To UBound(m_Settings, 1)
        If m_Settings(i, 0) = keyName Then
            SettingExists = True
            Exit Function
        End If
    Next i
    SettingExists = False
End Function
Public Property Get SettingCount() As Long
    If IsEmpty(m_Settings) Then
        SettingCount = 0
    Else
        SettingCount = UBound(m_Settings, 1) + 1
    End If
End Property</code></pre>
<h2 id="2-settings-backup-and-restore">2. Settings Backup and Restore</h2>
<pre><code class="language-vbnet">Type SettingsBackup
    AppName As String
    Section As String
    Settings As Variant
    BackupDate As Date
End Type
Function BackupSettings(appName As String, section As String) As SettingsBackup
    Dim backup As SettingsBackup
    backup.AppName = appName
    backup.Section = section
    backup.Settings = GetAllSettings(appName, section)
    backup.BackupDate = Now
    BackupSettings = backup
End Function
Sub RestoreSettings(backup As SettingsBackup)
    Dim i As Long
    If IsEmpty(backup.Settings) Then
        MsgBox &quot;No settings to restore&quot;
        Exit Sub
    End If
    &#x27; Clear existing settings first
    DeleteSetting backup.AppName, backup.Section
    &#x27; Restore backed up settings
    For i = LBound(backup.Settings, 1) To UBound(backup.Settings, 1)
        SaveSetting backup.AppName, backup.Section, _
                   backup.Settings(i, 0), backup.Settings(i, 1)
    Next i
    MsgBox &quot;Settings restored from &quot; &amp; Format(backup.BackupDate, &quot;yyyy-mm-dd hh:nn:ss&quot;)
End Sub</code></pre>
<h2 id="3-settings-encryptiondecryption">3. Settings Encryption/Decryption</h2>
<pre><code class="language-vbnet">Function GetEncryptedSettings(appName As String, section As String, _
                              password As String) As Variant
    Dim settings As Variant
    Dim decrypted() As String
    Dim i As Long
    settings = GetAllSettings(appName, section)
    If IsEmpty(settings) Then
        GetEncryptedSettings = Empty
        Exit Function
    End If
    ReDim decrypted(LBound(settings, 1) To UBound(settings, 1), 0 To 1)
    For i = LBound(settings, 1) To UBound(settings, 1)
        decrypted(i, 0) = settings(i, 0)
        decrypted(i, 1) = DecryptString(settings(i, 1), password)
    Next i
    GetEncryptedSettings = decrypted
End Function
Function DecryptString(encrypted As String, password As String) As String
    &#x27; Simple XOR encryption for demonstration
    Dim i As Long
    Dim result As String
    Dim keyChar As Integer
    result = &quot;&quot;
    For i = 1 To Len(encrypted)
        keyChar = Asc(Mid(password, ((i - 1) Mod Len(password)) + 1, 1))
        result = result &amp; Chr(Asc(Mid(encrypted, i, 1)) Xor keyChar)
    Next i
    DecryptString = result
End Function</code></pre>
<h2 id="4-multi-section-settings-loader">4. Multi-Section Settings Loader</h2>
<pre><code class="language-vbnet">Function LoadMultipleSections(appName As String, _
                              sections() As String) As Collection
    Dim allSettings As New Collection
    Dim i As Long
    Dim sectionSettings As Variant
    For i = LBound(sections) To UBound(sections)
        sectionSettings = GetAllSettings(appName, sections(i))
        If Not IsEmpty(sectionSettings) Then
            allSettings.Add sectionSettings, sections(i)
        End If
    Next i
    Set LoadMultipleSections = allSettings
End Function
&#x27; Usage
Sub LoadAllAppSettings()
    Dim sections() As String
    Dim allSettings As Collection
    Dim section As Variant
    sections = Split(&quot;General,Display,Network,Security&quot;, &quot;,&quot;)
    Set allSettings = LoadMultipleSections(App.Title, sections)
    For Each section In allSettings
        Debug.Print &quot;Section has &quot; &amp; (UBound(section, 1) + 1) &amp; &quot; settings&quot;
    Next
End Sub</code></pre>
<h2 id="5-settings-change-detection">5. Settings Change Detection</h2>
<pre><code class="language-vbnet">Type SettingsSnapshot
    Settings As Variant
    Timestamp As Date
End Type
Private m_LastSnapshot As SettingsSnapshot
Function TakeSnapshot(appName As String, section As String) As SettingsSnapshot
    Dim snapshot As SettingsSnapshot
    snapshot.Settings = GetAllSettings(appName, section)
    snapshot.Timestamp = Now
    TakeSnapshot = snapshot
End Function
Function DetectChanges(appName As String, section As String) As Boolean
    Dim currentSettings As Variant
    Dim i As Long
    Dim changed As Boolean
    currentSettings = GetAllSettings(appName, section)
    &#x27; Check if both are empty
    If IsEmpty(m_LastSnapshot.Settings) And IsEmpty(currentSettings) Then
        DetectChanges = False
        Exit Function
    End If
    &#x27; Check if one is empty
    If IsEmpty(m_LastSnapshot.Settings) Or IsEmpty(currentSettings) Then
        DetectChanges = True
        Exit Function
    End If
    &#x27; Check if different sizes
    If UBound(m_LastSnapshot.Settings, 1) &lt;&gt; UBound(currentSettings, 1) Then
        DetectChanges = True
        Exit Function
    End If
    &#x27; Compare values
    changed = False
    For i = LBound(currentSettings, 1) To UBound(currentSettings, 1)
        If currentSettings(i, 0) &lt;&gt; m_LastSnapshot.Settings(i, 0) Or _
           currentSettings(i, 1) &lt;&gt; m_LastSnapshot.Settings(i, 1) Then
            changed = True
            Exit For
        End If
    Next i
    DetectChanges = changed
End Function</code></pre>
<h2 id="6-settings-validation-framework">6. Settings Validation Framework</h2>
<pre><code class="language-vbnet">Type ValidationRule
    KeyName As String
    DataType As String  &#x27; &quot;String&quot;, &quot;Integer&quot;, &quot;Boolean&quot;, &quot;Date&quot;
    MinValue As Variant
    MaxValue As Variant
    Required As Boolean
End Type
Function ValidateAllSettings(appName As String, section As String, _
                             rules() As ValidationRule) As Collection
    Dim settings As Variant
    Dim errors As New Collection
    Dim i As Long, j As Long
    Dim found As Boolean
    Dim settingValue As String
    settings = GetAllSettings(appName, section)
    &#x27; Check each rule
    For i = LBound(rules) To UBound(rules)
        found = False
        If Not IsEmpty(settings) Then
            For j = LBound(settings, 1) To UBound(settings, 1)
                If settings(j, 0) = rules(i).KeyName Then
                    found = True
                    settingValue = settings(j, 1)
                    &#x27; Validate data type and range
                    If Not ValidateValue(settingValue, rules(i)) Then
                        errors.Add &quot;Invalid value for &quot; &amp; rules(i).KeyName
                    End If
                    Exit For
                End If
            Next j
        End If
        If Not found And rules(i).Required Then
            errors.Add &quot;Missing required setting: &quot; &amp; rules(i).KeyName
        End If
    Next i
    Set ValidateAllSettings = errors
End Function
Function ValidateValue(value As String, rule As ValidationRule) As Boolean
    Select Case rule.DataType
        Case &quot;Integer&quot;
            If Not IsNumeric(value) Then
                ValidateValue = False
            Else
                Dim intVal As Long
                intVal = CLng(value)
                ValidateValue = (intVal &gt;= rule.MinValue And intVal &lt;= rule.MaxValue)
            End If
        Case &quot;Boolean&quot;
            ValidateValue = (value = &quot;True&quot; Or value = &quot;False&quot;)
        Case Else
            ValidateValue = True
    End Select
End Function</code></pre>
<h1 id="error-handling">Error Handling</h1>
<pre><code class="language-vbnet">Function SafeGetAllSettings(appName As String, section As String) As Variant
    On Error GoTo ErrorHandler
    Dim settings As Variant
    settings = GetAllSettings(appName, section)
    SafeGetAllSettings = settings
    Exit Function
ErrorHandler:
    Debug.Print &quot;Error retrieving settings: &quot; &amp; Err.Description
    SafeGetAllSettings = Empty
End Function</code></pre>
<p>Common issues:
- <strong>Empty return value</strong>: Section or application does not exist in registry
- <strong>Registry access denied</strong>: Insufficient permissions to read registry
- <strong>Invalid section name</strong>: Special characters or invalid path</p>
<h1 id="performance-considerations">Performance Considerations</h1>
<ul>
<li><code>GetAllSettings</code> reads from the Windows registry, which is relatively fast</li>
<li>For frequently accessed settings, consider caching the results</li>
<li>Reading all settings at once is more efficient than multiple <code>GetSetting</code> calls</li>
<li>Registry access can be affected by antivirus software</li>
<li>Consider using INI files or XML for cross-platform compatibility</li>
</ul>
<h1 id="best-practices">Best Practices</h1>
<ol>
<li><strong>Always check for Empty</strong> before using the returned array</li>
<li><strong>Use meaningful section names</strong> to organize settings logically</li>
<li><strong>Cache settings</strong> in memory if accessed frequently</li>
<li><strong>Validate settings</strong> after retrieval</li>
<li><strong>Provide defaults</strong> when settings don't exist</li>
<li><strong>Document registry structure</strong> for your application</li>
<li><strong>Consider cleanup</strong> - use <code>DeleteSetting</code> when settings are no longer needed</li>
</ol>
<h1 id="comparison-with-other-functions">Comparison with Other Functions</h1>
<h2 id="getallsettings-vs-getsetting"><code>GetAllSettings</code> vs <code>GetSetting</code></h2>
<pre><code class="language-vbnet">&#x27; GetAllSettings - Retrieve all settings at once
Dim allSettings As Variant
allSettings = GetAllSettings(&quot;MyApp&quot;, &quot;Config&quot;)
&#x27; GetSetting - Retrieve one setting at a time
Dim value As String
value = GetSetting(&quot;MyApp&quot;, &quot;Config&quot;, &quot;Theme&quot;, &quot;Default&quot;)</code></pre>
<h2 id="getallsettings-vs-file-based-storage"><code>GetAllSettings</code> vs File-Based Storage</h2>
<pre><code class="language-vbnet">&#x27; GetAllSettings - Windows registry
settings = GetAllSettings(App.Title, &quot;Settings&quot;)
&#x27; File-based - INI file or XML (more portable)
&#x27; Requires custom parsing code</code></pre>
<h1 id="limitations">Limitations</h1>
<ul>
<li>Windows-specific (uses Windows registry)</li>
<li>Limited to <code>HKEY_CURRENT_USER</code> hive</li>
<li><code>String</code> values only (need to parse numbers, dates, etc.)</li>
<li>Registry size limits (though rarely hit in practice)</li>
<li>No built-in encryption or security</li>
<li>Requires appropriate registry permissions</li>
<li>Not suitable for large amounts of data</li>
<li>Two-dimensional array only (fixed structure)</li>
</ul>
<h1 id="registry-location">Registry Location</h1>
<p>Settings are stored at:</p>
<pre><code class="language-text">HKEY_CURRENT_USER\Software\VB and VBA Program Settings\appname\section</code></pre>
<h1 id="related-functions">Related Functions</h1>
<ul>
<li><code>GetSetting</code> - Returns a single key setting from the registry</li>
<li><code>SaveSetting</code> - Saves or creates an application entry in the registry</li>
<li><code>DeleteSetting</code> - Deletes a section or key setting from the registry</li>
<li><code>Environ</code> - Returns the string associated with an operating system environment variable</li>
<li><code>Command</code> - Returns the command-line arguments</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 Environment</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>