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
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
<!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 - msgbox - Interaction">
    <title>msgbox - Interaction - 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/interaction/index.html">Interaction</a> / msgbox</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="msgbox-function">MsgBox Function</h1>
<p>Displays a message in a dialog box, waits for the user to click a button, and returns an Integer indicating which button the user clicked.</p>
<h2 id="syntax">Syntax</h2>
<pre><code class="language-vbnet">MsgBox(prompt, [buttons], [title], [helpfile], [context])</code></pre>
<h2 id="parameters">Parameters</h2>
<ul>
<li><strong>prompt</strong> (Required) - String expression displayed as the message in the dialog box. Maximum length is approximately 1024 characters, depending on the width of the characters used. If prompt consists of more than one line, you can separate the lines using a carriage return character (Chr(13)), a linefeed character (Chr(10)), or a carriage return-linefeed character combination (vbCrLf) between each line.</li>
<li><strong>buttons</strong> (Optional) - Numeric expression that is the sum of values specifying the number and type of buttons to display, the icon style to use, the identity of the default button, and the modality of the message box. If omitted, the default value for buttons is 0.</li>
<li><strong>title</strong> (Optional) - String expression displayed in the title bar of the dialog box. If you omit title, the application name is placed in the title bar.</li>
<li><strong>helpfile</strong> (Optional) - String expression that identifies the Help file to use to provide context-sensitive Help for the dialog box. If helpfile is provided, context must also be provided.</li>
<li><strong>context</strong> (Optional) - Numeric expression that is the Help context number assigned to the appropriate Help topic by the Help author. If context is provided, helpfile must also be provided.</li>
</ul>
<h2 id="return-value">Return Value</h2>
<p>Returns an <strong>Integer</strong> representing which button was clicked:
- <strong>vbOK (1)</strong> - OK button was clicked
- <strong>vbCancel (2)</strong> - Cancel button was clicked
- <strong>vbAbort (3)</strong> - Abort button was clicked
- <strong>vbRetry (4)</strong> - Retry button was clicked
- <strong>vbIgnore (5)</strong> - Ignore button was clicked
- <strong>vbYes (6)</strong> - Yes button was clicked
- <strong>vbNo (7)</strong> - No button was clicked</p>
<h2 id="remarks">Remarks</h2>
<p>The <code>MsgBox</code> function is one of the most commonly used VB6 functions for user interaction and debugging.
It provides a simple way to display messages, warnings, errors, and questions to the user.</p>
<h3 id="button-constants-first-group-buttons">Button Constants (First Group - Buttons):</h3>
<ul>
<li><strong>vbOKOnly (0)</strong> - Display OK button only (default)</li>
<li><strong>vbOKCancel (1)</strong> - Display OK and Cancel buttons</li>
<li><strong>vbAbortRetryIgnore (2)</strong> - Display Abort, Retry, and Ignore buttons</li>
<li><strong>vbYesNoCancel (3)</strong> - Display Yes, No, and Cancel buttons</li>
<li><strong>vbYesNo (4)</strong> - Display Yes and No buttons</li>
<li><strong>vbRetryCancel (5)</strong> - Display Retry and Cancel buttons</li>
</ul>
<h3 id="icon-constants-second-group-icons">Icon Constants (Second Group - Icons):</h3>
<ul>
<li><strong>vbCritical (16)</strong> - Display Critical Message icon (red X)</li>
<li><strong>vbQuestion (32)</strong> - Display Warning Query icon (question mark)</li>
<li><strong>vbExclamation (48)</strong> - Display Warning Message icon (exclamation point)</li>
<li><strong>vbInformation (64)</strong> - Display Information Message icon (lowercase i)</li>
</ul>
<h3 id="default-button-constants-third-group-default-button">Default Button Constants (Third Group - Default Button):</h3>
<ul>
<li><strong>vbDefaultButton1 (0)</strong> - First button is default (default)</li>
<li><strong>vbDefaultButton2 (256)</strong> - Second button is default</li>
<li><strong>vbDefaultButton3 (512)</strong> - Third button is default</li>
<li><strong>vbDefaultButton4 (768)</strong> - Fourth button is default</li>
</ul>
<h3 id="modality-constants-fourth-group-modality">Modality Constants (Fourth Group - Modality):</h3>
<ul>
<li><strong>vbApplicationModal (0)</strong> - Application modal; the user must respond to the message box before continuing work in the current application (default)</li>
<li><strong>vbSystemModal (4096)</strong> - System modal; all applications are suspended until the user responds to the message box</li>
</ul>
<h3 id="other-constants-fifth-group-other">Other Constants (Fifth Group - Other):</h3>
<ul>
<li><strong>vbMsgBoxHelpButton (16384)</strong> - Adds Help button to the message box</li>
<li><strong>vbMsgBoxSetForeground (65536)</strong> - Specifies the message box window as the foreground window</li>
<li><strong>vbMsgBoxRight (524288)</strong> - Text is right-aligned</li>
<li><strong>vbMsgBoxRtlReading (1048576)</strong> - Specifies text should appear as right-to-left reading on Hebrew and Arabic systems</li>
</ul>
<h3 id="key-characteristics">Key Characteristics:</h3>
<ul>
<li>Blocks execution until user responds (modal dialog)</li>
<li>Return value can be ignored if not needed</li>
<li>Can combine button constants using addition or Or operator</li>
<li>Maximum prompt length is approximately 1024 characters</li>
<li>Can display multi-line messages using vbCrLf</li>
<li>If user presses Escape key, acts as clicking Cancel button</li>
<li>Can invoke help file if helpfile and context parameters provided</li>
<li>Common for debugging with Debug.Print alternative</li>
</ul>
<h3 id="common-use-cases">Common Use Cases:</h3>
<ul>
<li>Display informational messages to users</li>
<li>Show error messages and warnings</li>
<li>Ask yes/no questions for user confirmation</li>
<li>Debugging by displaying variable values</li>
<li>Alert users of important events</li>
<li>Confirm destructive operations</li>
<li>Display results of calculations</li>
<li>Provide feedback on operation completion</li>
</ul>
<h2 id="typical-uses">Typical Uses</h2>
<ol>
<li><strong>Simple Messages</strong> - Display information to the user</li>
<li><strong>Error Handling</strong> - Show error messages with appropriate icons</li>
<li><strong>User Confirmation</strong> - Ask yes/no questions before proceeding</li>
<li><strong>Debugging</strong> - Display variable values during development</li>
<li><strong>Operation Feedback</strong> - Inform user of completion or status</li>
<li><strong>Validation Warnings</strong> - Alert user to invalid input</li>
<li><strong>Save Prompts</strong> - Ask user to save changes before closing</li>
<li><strong>Delete Confirmations</strong> - Verify user wants to delete items</li>
</ol>
<h2 id="basic-examples">Basic Examples</h2>
<pre><code class="language-vbnet">&#x27; Example 1: Simple message
MsgBox &quot;Operation completed successfully!&quot;</code></pre>
<pre><code class="language-vbnet">&#x27; Example 2: Message with title and icon
MsgBox &quot;File not found!&quot;, vbExclamation, &quot;Error&quot;</code></pre>
<pre><code class="language-vbnet">&#x27; Example 3: Yes/No question
Dim result As Integer
result = MsgBox(&quot;Do you want to save changes?&quot;, vbYesNo + vbQuestion, &quot;Confirm&quot;)
If result = vbYes Then
    &#x27; Save changes
End If</code></pre>
<pre><code class="language-vbnet">&#x27; Example 4: Multi-line message
MsgBox &quot;Line 1&quot; &amp; vbCrLf &amp; &quot;Line 2&quot; &amp; vbCrLf &amp; &quot;Line 3&quot;, vbInformation, &quot;Multi-line&quot;</code></pre>
<h2 id="common-patterns">Common Patterns</h2>
<pre><code class="language-vbnet">&#x27; Pattern 1: Simple error message
Sub ShowError(message As String)
    MsgBox message, vbCritical, &quot;Error&quot;
End Sub</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 2: Confirmation with default No
Function ConfirmAction(message As String) As Boolean
    Dim result As Integer
    result = MsgBox(message, vbYesNo + vbQuestion + vbDefaultButton2, &quot;Confirm&quot;)
    ConfirmAction = (result = vbYes)
End Function</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 3: Save prompt
Function PromptToSave(fileName As String) As Integer
    Dim msg As String
    msg = &quot;Save changes to &quot; &amp; fileName &amp; &quot;?&quot;
    PromptToSave = MsgBox(msg, vbYesNoCancel + vbQuestion, &quot;Save Changes&quot;)
End Function</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 4: Display detailed error
Sub ShowDetailedError(errorMsg As String, errorNumber As Long)
    Dim msg As String
    msg = &quot;Error #&quot; &amp; errorNumber &amp; vbCrLf &amp; vbCrLf &amp; errorMsg
    MsgBox msg, vbCritical + vbOKOnly, &quot;Application Error&quot;
End Sub</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 5: Information with sound
Sub ShowInfo(message As String)
    MsgBox message, vbInformation + vbOKOnly, &quot;Information&quot;
    &#x27; vbInformation plays the system information sound
End Sub</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 6: Retry/Cancel operation
Function RetryOperation(operation As String) As Boolean
    Dim result As Integer
    Dim msg As String
    msg = &quot;Failed to &quot; &amp; operation &amp; &quot;.&quot; &amp; vbCrLf &amp; &quot;Would you like to retry?&quot;
    result = MsgBox(msg, vbRetryCancel + vbExclamation, &quot;Operation Failed&quot;)
    RetryOperation = (result = vbRetry)
End Function</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 7: Debug variable display
Sub DebugShow(variableName As String, value As Variant)
    #If DEBUG_MODE Then
        MsgBox variableName &amp; &quot; = &quot; &amp; CStr(value), vbInformation, &quot;Debug&quot;
    #End If
End Sub</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 8: Abort/Retry/Ignore pattern
Function HandleError(errorMsg As String) As Integer
    Dim msg As String
    msg = &quot;An error occurred:&quot; &amp; vbCrLf &amp; vbCrLf &amp; errorMsg &amp; vbCrLf &amp; vbCrLf &amp; _
          &quot;Abort: Stop operation&quot; &amp; vbCrLf &amp; _
          &quot;Retry: Try again&quot; &amp; vbCrLf &amp; _
          &quot;Ignore: Continue anyway&quot;
    HandleError = MsgBox(msg, vbAbortRetryIgnore + vbCritical, &quot;Error&quot;)
End Function</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 9: Formatted message with details
Sub ShowOperationResult(operation As String, recordCount As Long, elapsedTime As Double)
    Dim msg As String
    msg = &quot;Operation: &quot; &amp; operation &amp; vbCrLf &amp; _
          &quot;Records processed: &quot; &amp; recordCount &amp; vbCrLf &amp; _
          &quot;Time elapsed: &quot; &amp; Format(elapsedTime, &quot;0.00&quot;) &amp; &quot; seconds&quot;
    MsgBox msg, vbInformation, &quot;Operation Complete&quot;
End Sub</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 10: Custom button selection handler
Sub ProcessUserChoice(prompt As String)
    Dim result As Integer
    result = MsgBox(prompt, vbYesNoCancel + vbQuestion, &quot;Choose Option&quot;)
    Select Case result
        Case vbYes
            &#x27; Handle Yes
        Case vbNo
            &#x27; Handle No
        Case vbCancel
            &#x27; Handle Cancel
    End Select
End Sub</code></pre>
<h2 id="advanced-usage">Advanced Usage</h2>
<h3 id="example-1-smart-message-box-wrapper">Example 1: Smart Message Box Wrapper</h3>
<pre><code class="language-vbnet">&#x27; Module: SmartMessageBox
&#x27; Provides enhanced message box functionality with logging and customization
Option Explicit
Private m_logEnabled As Boolean
Private m_defaultTitle As String
Public Sub Initialize(appName As String, enableLogging As Boolean)
    m_defaultTitle = appName
    m_logEnabled = enableLogging
End Sub
Public Function ShowMessage(message As String, _
                           Optional msgType As VbMsgBoxStyle = vbInformation, _
                           Optional title As String = &quot;&quot;) As Integer
    Dim actualTitle As String
    If Len(title) = 0 Then
        actualTitle = m_defaultTitle
    Else
        actualTitle = title
    End If
    If m_logEnabled Then
        LogMessage message, msgType
    End If
    ShowMessage = MsgBox(message, msgType, actualTitle)
End Function
Public Function Confirm(message As String, _
                       Optional defaultToNo As Boolean = False) As Boolean
    Dim buttons As VbMsgBoxStyle
    Dim result As Integer
    buttons = vbYesNo + vbQuestion
    If defaultToNo Then
        buttons = buttons + vbDefaultButton2
    End If
    result = MsgBox(message, buttons, m_defaultTitle)
    Confirm = (result = vbYes)
End Function
Public Sub ShowError(message As String, Optional errorNumber As Long = 0)
    Dim msg As String
    If errorNumber &lt;&gt; 0 Then
        msg = &quot;Error #&quot; &amp; errorNumber &amp; vbCrLf &amp; vbCrLf &amp; message
    Else
        msg = message
    End If
    If m_logEnabled Then
        LogMessage &quot;ERROR: &quot; &amp; msg, vbCritical
    End If
    MsgBox msg, vbCritical, m_defaultTitle
End Sub
Public Sub ShowWarning(message As String)
    If m_logEnabled Then
        LogMessage &quot;WARNING: &quot; &amp; message, vbExclamation
    End If
    MsgBox message, vbExclamation, m_defaultTitle
End Sub
Public Sub ShowInfo(message As String)
    If m_logEnabled Then
        LogMessage &quot;INFO: &quot; &amp; message, vbInformation
    End If
    MsgBox message, vbInformation, m_defaultTitle
End Sub
Private Sub LogMessage(message As String, msgType As VbMsgBoxStyle)
    &#x27; Log to file or debug window
    Debug.Print Now &amp; &quot; - &quot; &amp; GetMessageTypeString(msgType) &amp; &quot;: &quot; &amp; message
End Sub
Private Function GetMessageTypeString(msgType As VbMsgBoxStyle) As String
    If (msgType And vbCritical) = vbCritical Then
        GetMessageTypeString = &quot;ERROR&quot;
    ElseIf (msgType And vbExclamation) = vbExclamation Then
        GetMessageTypeString = &quot;WARNING&quot;
    ElseIf (msgType And vbQuestion) = vbQuestion Then
        GetMessageTypeString = &quot;QUESTION&quot;
    Else
        GetMessageTypeString = &quot;INFO&quot;
    End If
End Function</code></pre>
<h3 id="example-2-message-box-builder-class">Example 2: Message Box Builder Class</h3>
<pre><code class="language-vbnet">&#x27; Class: MessageBoxBuilder
&#x27; Fluent interface for building complex message boxes
Option Explicit
Private m_prompt As String
Private m_title As String
Private m_buttons As VbMsgBoxStyle
Private m_icon As VbMsgBoxStyle
Private m_defaultButton As VbMsgBoxStyle
Private Sub Class_Initialize()
    m_prompt = &quot;&quot;
    m_title = &quot;&quot;
    m_buttons = vbOKOnly
    m_icon = 0
    m_defaultButton = vbDefaultButton1
End Sub
Public Function WithPrompt(prompt As String) As MessageBoxBuilder
    m_prompt = prompt
    Set WithPrompt = Me
End Function
Public Function WithTitle(title As String) As MessageBoxBuilder
    m_title = title
    Set WithTitle = Me
End Function
Public Function WithButtons(buttons As VbMsgBoxStyle) As MessageBoxBuilder
    m_buttons = buttons
    Set WithButtons = Me
End Function
Public Function WithIcon(icon As VbMsgBoxStyle) As MessageBoxBuilder
    m_icon = icon
    Set WithIcon = Me
End Function
Public Function WithDefaultButton(defaultButton As VbMsgBoxStyle) As MessageBoxBuilder
    m_defaultButton = defaultButton
    Set WithDefaultButton = Me
End Function
Public Function AddLine(text As String) As MessageBoxBuilder
    If Len(m_prompt) &gt; 0 Then
        m_prompt = m_prompt &amp; vbCrLf
    End If
    m_prompt = m_prompt &amp; text
    Set AddLine = Me
End Function
Public Function Show() As Integer
    Dim style As VbMsgBoxStyle
    style = m_buttons Or m_icon Or m_defaultButton
    Show = MsgBox(m_prompt, style, m_title)
End Function
&#x27; Convenience methods
Public Function ShowError(errorMsg As String) As Integer
    Set WithPrompt(errorMsg)
    Set WithIcon(vbCritical)
    ShowError = Show()
End Function
Public Function AskYesNo(question As String) As Boolean
    Set WithPrompt(question)
    Set WithButtons(vbYesNo)
    Set WithIcon(vbQuestion)
    AskYesNo = (Show() = vbYes)
End Function</code></pre>
<h3 id="example-3-message-queue-manager">Example 3: Message Queue Manager</h3>
<pre><code class="language-vbnet">&#x27; Class: MessageQueueManager
&#x27; Manages queued messages to avoid overwhelming the user
Option Explicit
Private Type QueuedMessage
    prompt As String
    buttons As VbMsgBoxStyle
    title As String
    timestamp As Date
End Type
Private m_queue As Collection
Private m_maxQueueSize As Long
Private m_autoShowDelay As Long &#x27; milliseconds
Private Sub Class_Initialize()
    Set m_queue = New Collection
    m_maxQueueSize = 10
    m_autoShowDelay = 1000
End Sub
Public Sub QueueMessage(prompt As String, _
                       Optional buttons As VbMsgBoxStyle = vbOKOnly, _
                       Optional title As String = &quot;Message&quot;)
    Dim msg As QueuedMessage
    msg.prompt = prompt
    msg.buttons = buttons
    msg.title = title
    msg.timestamp = Now
    If m_queue.Count &gt;= m_maxQueueSize Then
        &#x27; Remove oldest message
        m_queue.Remove 1
    End If
    m_queue.Add msg
End Sub
Public Sub ShowNextMessage() As Integer
    Dim msg As QueuedMessage
    If m_queue.Count &gt; 0 Then
        msg = m_queue(1)
        m_queue.Remove 1
        ShowNextMessage = MsgBox(msg.prompt, msg.buttons, msg.title)
    End If
End Sub
Public Sub ShowAllMessages()
    Dim msg As QueuedMessage
    Dim i As Long
    For i = 1 To m_queue.Count
        msg = m_queue(i)
        MsgBox msg.prompt, msg.buttons, msg.title
    Next i
    Set m_queue = New Collection
End Sub
Public Function GetQueuedCount() As Long
    GetQueuedCount = m_queue.Count
End Function
Public Sub ShowSummary()
    Dim msg As String
    Dim qMsg As QueuedMessage
    Dim i As Long
    If m_queue.Count = 0 Then
        MsgBox &quot;No queued messages&quot;, vbInformation
        Exit Sub
    End If
    msg = &quot;Queued Messages (&quot; &amp; m_queue.Count &amp; &quot;):&quot; &amp; vbCrLf &amp; vbCrLf
    For i = 1 To m_queue.Count
        qMsg = m_queue(i)
        msg = msg &amp; i &amp; &quot;. &quot; &amp; Left(qMsg.prompt, 50)
        If Len(qMsg.prompt) &gt; 50 Then msg = msg &amp; &quot;...&quot;
        msg = msg &amp; vbCrLf
    Next i
    MsgBox msg, vbInformation, &quot;Message Queue&quot;
End Sub</code></pre>
<h3 id="example-4-auto-dismissing-message-box-timer-based">Example 4: Auto-Dismissing Message Box (Timer-based)</h3>
<pre><code class="language-vbnet">&#x27; Module: TimedMessageBox
&#x27; Shows message boxes that auto-dismiss after timeout
Option Explicit
#If Win32 Then
    Private Declare Function MessageBoxTimeout Lib &quot;user32&quot; Alias &quot;MessageBoxTimeoutA&quot; ( _
        ByVal hwnd As Long, _
        ByVal lpText As String, _
        ByVal lpCaption As String, _
        ByVal uType As Long, _
        ByVal wLanguageId As Long, _
        ByVal dwMilliseconds As Long) As Long
#End If
Public Function MsgBoxTimed(prompt As String, _
                           Optional buttons As VbMsgBoxStyle = vbOKOnly, _
                           Optional title As String = &quot;&quot;, _
                           Optional timeout As Long = 5000) As Integer
    #If Win32 Then
        &#x27; Use Windows API for timed message box
        MsgBoxTimed = MessageBoxTimeout(0, prompt, title, buttons, 0, timeout)
    #Else
        &#x27; Fallback to regular MsgBox
        MsgBoxTimed = MsgBox(prompt, buttons, title)
    #End If
End Function
Public Sub ShowTimedInfo(message As String, Optional seconds As Long = 3)
    MsgBoxTimed message, vbInformation, &quot;Information&quot;, seconds * 1000
End Sub
Public Sub ShowTimedWarning(message As String, Optional seconds As Long = 5)
    MsgBoxTimed message, vbExclamation, &quot;Warning&quot;, seconds * 1000
End Sub
Public Function ConfirmTimed(message As String, Optional seconds As Long = 10) As Boolean
    Dim result As Integer
    result = MsgBoxTimed(message, vbYesNo + vbQuestion, &quot;Confirm&quot;, seconds * 1000)
    ConfirmTimed = (result = vbYes)
End Function</code></pre>
<h2 id="error-handling">Error Handling</h2>
<pre><code class="language-vbnet">&#x27; MsgBox rarely fails, but handle potential issues:
On Error Resume Next
result = MsgBox(userInput, vbOKOnly, &quot;Message&quot;)
If Err.Number &lt;&gt; 0 Then
    Debug.Print &quot;MsgBox error: &quot; &amp; Err.Description
    &#x27; Possibly userInput was too long or contained invalid characters
End If
On Error GoTo 0</code></pre>
<h2 id="performance-considerations">Performance Considerations</h2>
<ul>
<li><code>MsgBox</code> blocks execution - not suitable for background operations</li>
<li>For debugging, consider Debug.Print as faster alternative</li>
<li>Avoid <code>MsgBox</code> in loops - very slow and annoying to users</li>
<li>For status updates, use status bar or progress form instead</li>
<li>System modal (vbSystemModal) blocks ALL applications - use sparingly</li>
<li>Long prompts may be truncated - keep messages concise</li>
<li>Each <code>MsgBox</code> call creates and destroys a window - has overhead</li>
</ul>
<h2 id="best-practices">Best Practices</h2>
<ol>
<li><strong>Keep messages concise</strong> - Users don't read long messages</li>
<li><strong>Use appropriate icons</strong> - Help users understand message severity</li>
<li><strong>Provide clear actions</strong> - Button choices should be obvious</li>
<li><strong>Use meaningful titles</strong> - Don't just say "Error" or "Message"</li>
<li><strong>Avoid <code>MsgBox</code> in loops</strong> - Queue messages or use alternative feedback</li>
<li><strong>Handle all return values</strong> - Check what button user clicked</li>
<li><strong>Use vbCrLf for readability</strong> - Multi-line messages are easier to read</li>
<li><strong>Consider default button</strong> - Make safe choice the default</li>
<li><strong>Test message length</strong> - Very long messages may not display well</li>
<li><strong>Use for errors, not debugging</strong> - Prefer Debug.Print for development</li>
</ol>
<h2 id="comparison-with-alternatives">Comparison with Alternatives</h2>
<table>
<thead>
<tr>
<th>Approach</th>
<th>Pros</th>
<th>Cons</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong><code>MsgBox</code></strong></td>
<td>Simple, built-in, modal</td>
<td>Blocks execution, limited customization</td>
</tr>
<tr>
<td><strong>Custom Form</strong></td>
<td>Full control, rich UI</td>
<td>More code, more complex</td>
</tr>
<tr>
<td><strong>Debug.Print</strong></td>
<td>Non-blocking, fast</td>
<td>Not visible to end users</td>
</tr>
<tr>
<td><strong>Status Bar</strong></td>
<td>Non-blocking, professional</td>
<td>Limited message length, less visible</td>
</tr>
<tr>
<td><strong><code>InputBox</code></strong></td>
<td>Gets user input</td>
<td>Only single-line text input</td>
</tr>
<tr>
<td><strong>Notification API</strong></td>
<td>Modern, non-blocking</td>
<td>Requires Windows 10+, more complex</td>
</tr>
</tbody>
</table>
<h2 id="statement-vs-function">Statement vs Function</h2>
<p><code>MsgBox</code> can be used as both a statement (no parentheses, no return value) and a function (with parentheses, returns value):</p>
<pre><code class="language-vbnet">&#x27; As a statement (no return value needed)
MsgBox &quot;Hello, World!&quot;
&#x27; As a function (capture return value)
result = MsgBox(&quot;Continue?&quot;, vbYesNo)</code></pre>
<h2 id="platform-notes">Platform Notes</h2>
<ul>
<li>Available in VBA (Excel, Access, Word, etc.)</li>
<li>Available in VB6</li>
<li>Available in <code>VBScript</code> (limited - no named constants in <code>VBScript</code>)</li>
<li>Uses Windows common dialog</li>
<li>Appearance varies by Windows version</li>
<li>Icons and sounds defined by Windows theme</li>
<li>Right-to-left reading supported on appropriate systems</li>
</ul>
<h2 id="limitations">Limitations</h2>
<ul>
<li>Blocks execution (modal)</li>
<li>Limited to approximately 1024 characters in prompt</li>
<li>Cannot customize button text (e.g., can't change "Yes" to "Accept")</li>
<li>Cannot add custom icons</li>
<li>Cannot resize or reposition the dialog</li>
<li>No timeout capability (without API calls)</li>
<li>No checkboxes or radio buttons</li>
<li>Cannot validate input (use <code>InputBox</code> or custom form for that)</li>
</ul>
<h2 id="related-functions">Related Functions</h2>
<ul>
<li><strong><code>InputBox</code></strong> - Gets text input from user</li>
<li><strong>Debug.Print</strong> - Prints to Immediate window (development only)</li>
<li><strong>Shell</strong> - Runs external programs</li>
<li><strong>Beep</strong> - Plays system beep sound</li>
<li><strong><code>SendKeys</code></strong> - Sends keystrokes to active window</li>
</ul>
<h2 id="vb6-parser-notes">VB6 Parser Notes</h2>
<p><code>MsgBox</code> can be used as both a statement and a function. When used as a function (with parentheses
and capturing return value), it is parsed as a <code>CallExpression</code>. When used as a statement (without
parentheses), it may be parsed differently. This module exists primarily for documentation purposes
to provide comprehensive reference material for VB6 developers working with user interaction and
message display operations.</p>
        </article>
        
        <div style="margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--border-color);">
            <p>
                <a href="index.html">← Back to Interaction</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>