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
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
//! # Shell Function
//!
//! Runs an executable program and returns a Variant (Double) representing the program's task ID if successful, or zero if unsuccessful.
//!
//! ## Syntax
//!
//! ```vb
//! Shell(pathname, [windowstyle])
//! ```
//!
//! ## Parameters
//!
//! - `pathname` - Required. String expression specifying the name of the program to execute, along with any required arguments or command-line switches. May include directory or folder path.
//! - `windowstyle` - Optional. Variant (Integer) corresponding to the style of the window in which the program is to be run. If omitted, the program is started minimized with focus.
//!
//! ## Window Style Values
//!
//! | Constant | Value | Description |
//! |----------|-------|-------------|
//! | vbHide | 0 | Window is hidden and focus is passed to the hidden window |
//! | vbNormalFocus | 1 | Window has focus and is restored to its original size and position |
//! | vbMinimizedFocus | 2 | Window is displayed as an icon with focus |
//! | vbMaximizedFocus | 3 | Window is maximized with focus |
//! | vbNormalNoFocus | 4 | Window is restored to most recent size and position; currently active window remains active |
//! | vbMinimizedNoFocus | 6 | Window is displayed as an icon; currently active window remains active |
//!
//! ## Return Value
//!
//! Returns a Variant (Double) containing the task ID of the started program:
//! - If successful: Returns the task ID (a unique identifier for the process)
//! - If unsuccessful: Returns 0
//! - Task ID can be used with `AppActivate` statement to give focus to the window
//!
//! ## Remarks
//!
//! The Shell function runs an executable program asynchronously. This means that a program started with Shell might not finish executing before the statements following the Shell function are executed.
//!
//! Key characteristics:
//! - Executes programs asynchronously (doesn't wait for completion)
//! - Returns immediately after starting the program
//! - Can launch any executable file (.exe, .com, .bat, .cmd, etc.)
//! - Can include command-line arguments in pathname
//! - Task ID can be used with `AppActivate` to switch focus
//! - If program cannot be started, returns 0
//! - On error, generates Error 5 (Invalid procedure call) or Error 53 (File not found)
//!
//! The pathname can include:
//! - Full path to executable: "C:\Windows\notepad.exe"
//! - Relative path: "..\..\tools\mytool.exe"
//! - Program in system PATH: "notepad.exe"
//! - Command with arguments: "notepad.exe C:\readme.txt"
//!
//! Important considerations:
//! - Shell executes asynchronously - use `AppActivate` or API calls to synchronize
//! - No direct way to know when shelled program terminates from VB6
//! - Can't capture standard output/error directly (use API or temp files)
//! - Security: Be cautious with user-supplied paths to avoid injection
//! - Long filenames with spaces should be enclosed in quotes
//!
//! ## Typical Uses
//!
//! 1. **Launch Applications**: Open external programs from your VB6 app
//! 2. **Open Documents**: Launch files with associated applications
//! 3. **Run Batch Files**: Execute .bat or .cmd scripts
//! 4. **Execute Commands**: Run command-line tools
//! 5. **System Tools**: Open Windows utilities (calc, notepad, etc.)
//! 6. **Background Tasks**: Start processes that run independently
//! 7. **Integration**: Interact with other applications
//! 8. **File Operations**: Use command-line tools for file manipulation
//!
//! ## Basic Examples
//!
//! ```vb
//! ' Example 1: Open Notepad
//! Dim taskId As Double
//! taskId = Shell("notepad.exe", vbNormalFocus)
//! If taskId = 0 Then
//!     MsgBox "Failed to start Notepad"
//! End If
//! ```
//!
//! ```vb
//! ' Example 2: Open file with Notepad
//! Dim taskId As Double
//! taskId = Shell("notepad.exe C:\readme.txt", vbNormalFocus)
//! ```
//!
//! ```vb
//! ' Example 3: Run Calculator maximized
//! Dim taskId As Double
//! taskId = Shell("calc.exe", vbMaximizedFocus)
//! ```
//!
//! ```vb
//! ' Example 4: Execute batch file hidden
//! Dim taskId As Double
//! taskId = Shell("C:\Scripts\backup.bat", vbHide)
//! ```
//!
//! ## Common Patterns
//!
//! ### Pattern 1: `SafeShell`
//! Execute program with error handling
//! ```vb
//! Function SafeShell(programPath As String, Optional windowStyle As Integer = vbNormalFocus) As Double
//!     On Error Resume Next
//!     SafeShell = Shell(programPath, windowStyle)
//!     
//!     If Err.Number <> 0 Then
//!         MsgBox "Error starting program: " & Err.Description, vbExclamation
//!         SafeShell = 0
//!     End If
//! End Function
//! ```
//!
//! ### Pattern 2: `ShellAndWait`
//! Execute program and wait for completion (using `AppActivate`)
//! ```vb
//! Function ShellAndWait(programPath As String, windowStyle As Integer) As Boolean
//!     Dim taskId As Double
//!     Dim startTime As Double
//!     
//!     On Error GoTo ErrorHandler
//!     
//!     taskId = Shell(programPath, windowStyle)
//!     If taskId = 0 Then
//!         ShellAndWait = False
//!         Exit Function
//!     End If
//!     
//!     ' Give the program time to start
//!     DoEvents
//!     
//!     ' Wait for program window to exist
//!     startTime = Timer
//!     Do While Timer - startTime < 30  ' 30 second timeout
//!         On Error Resume Next
//!         AppActivate taskId
//!         If Err.Number = 0 Then Exit Do
//!         Err.Clear
//!         DoEvents
//!     Loop
//!     
//!     ShellAndWait = True
//!     Exit Function
//!     
//! ErrorHandler:
//!     ShellAndWait = False
//! End Function
//! ```
//!
//! ### Pattern 3: `QuotePath`
//! Ensure path is properly quoted for spaces
//! ```vb
//! Function QuotePath(path As String) As String
//!     If InStr(path, " ") > 0 And Left(path, 1) <> """" Then
//!         QuotePath = """" & path & """"
//!     Else
//!         QuotePath = path
//!     End If
//! End Function
//!
//! ' Usage:
//! taskId = Shell(QuotePath("C:\Program Files\MyApp\app.exe"), vbNormalFocus)
//! ```
//!
//! ### Pattern 4: `OpenFileWithApp`
//! Open file with specific application
//! ```vb
//! Function OpenFileWithApp(appPath As String, filePath As String, _
//!                          Optional windowStyle As Integer = vbNormalFocus) As Boolean
//!     Dim commandLine As String
//!     Dim taskId As Double
//!     
//!     ' Quote paths if they contain spaces
//!     If InStr(appPath, " ") > 0 Then appPath = """" & appPath & """"
//!     If InStr(filePath, " ") > 0 Then filePath = """" & filePath & """"
//!     
//!     commandLine = appPath & " " & filePath
//!     
//!     On Error Resume Next
//!     taskId = Shell(commandLine, windowStyle)
//!     OpenFileWithApp = (taskId <> 0 And Err.Number = 0)
//! End Function
//! ```
//!
//! ### Pattern 5: `ExecuteCommand`
//! Execute command-line command
//! ```vb
//! Function ExecuteCommand(command As String, Optional waitSeconds As Integer = 0) As Double
//!     Dim taskId As Double
//!     Dim endTime As Double
//!     
//!     On Error GoTo ErrorHandler
//!     
//!     ' Run command via cmd.exe
//!     taskId = Shell("cmd.exe /c " & command, vbHide)
//!     
//!     If waitSeconds > 0 Then
//!         endTime = Timer + waitSeconds
//!         Do While Timer < endTime
//!             DoEvents
//!         Loop
//!     End If
//!     
//!     ExecuteCommand = taskId
//!     Exit Function
//!     
//! ErrorHandler:
//!     ExecuteCommand = 0
//! End Function
//! ```
//!
//! ### Pattern 6: `LaunchAndActivate`
//! Launch program and bring to front
//! ```vb
//! Function LaunchAndActivate(programPath As String) As Boolean
//!     Dim taskId As Double
//!     Dim attempts As Integer
//!     
//!     On Error Resume Next
//!     taskId = Shell(programPath, vbNormalFocus)
//!     
//!     If taskId = 0 Then
//!         LaunchAndActivate = False
//!         Exit Function
//!     End If
//!     
//!     ' Try to activate window
//!     For attempts = 1 To 10
//!         DoEvents
//!         AppActivate taskId
//!         If Err.Number = 0 Then
//!             LaunchAndActivate = True
//!             Exit Function
//!         End If
//!         Err.Clear
//!     Next attempts
//!     
//!     LaunchAndActivate = False
//! End Function
//! ```
//!
//! ### Pattern 7: `CheckProgramExists`
//! Verify program exists before shelling
//! ```vb
//! Function CheckProgramExists(programPath As String) As Boolean
//!     On Error Resume Next
//!     CheckProgramExists = (Dir(programPath) <> "")
//! End Function
//!
//! ' Usage:
//! If CheckProgramExists("C:\Tools\mytool.exe") Then
//!     taskId = Shell("C:\Tools\mytool.exe", vbNormalFocus)
//! Else
//!     MsgBox "Program not found"
//! End If
//! ```
//!
//! ### Pattern 8: `ShellWithTimeout`
//! Execute with timeout detection
//! ```vb
//! Function ShellWithTimeout(programPath As String, timeoutSeconds As Integer) As Boolean
//!     Dim taskId As Double
//!     Dim startTime As Double
//!     
//!     On Error GoTo ErrorHandler
//!     
//!     taskId = Shell(programPath, vbNormalFocus)
//!     If taskId = 0 Then
//!         ShellWithTimeout = False
//!         Exit Function
//!     End If
//!     
//!     startTime = Timer
//!     Do While Timer - startTime < timeoutSeconds
//!         DoEvents
//!     Loop
//!     
//!     ShellWithTimeout = True
//!     Exit Function
//!     
//! ErrorHandler:
//!     ShellWithTimeout = False
//! End Function
//! ```
//!
//! ### Pattern 9: `OpenDocument`
//! Open document with default application
//! ```vb
//! Function OpenDocument(filePath As String) As Boolean
//!     Dim taskId As Double
//!     
//!     On Error Resume Next
//!     
//!     ' Use "start" command to open with default app
//!     taskId = Shell("cmd.exe /c start """" """ & filePath & """", vbHide)
//!     
//!     OpenDocument = (taskId <> 0 And Err.Number = 0)
//! End Function
//! ```
//!
//! ### Pattern 10: `RunBatchFile`
//! Execute batch file with parameters
//! ```vb
//! Function RunBatchFile(batchPath As String, parameters As String, _
//!                       Optional hideWindow As Boolean = True) As Double
//!     Dim commandLine As String
//!     Dim windowStyle As Integer
//!     
//!     If InStr(batchPath, " ") > 0 Then
//!         commandLine = """" & batchPath & """"
//!     Else
//!         commandLine = batchPath
//!     End If
//!     
//!     If Len(parameters) > 0 Then
//!         commandLine = commandLine & " " & parameters
//!     End If
//!     
//!     windowStyle = IIf(hideWindow, vbHide, vbNormalFocus)
//!     
//!     On Error Resume Next
//!     RunBatchFile = Shell(commandLine, windowStyle)
//! End Function
//! ```
//!
//! ## Advanced Usage
//!
//! ### Example 1: `ProcessLauncher` Class
//! Manage launching and tracking external processes
//! ```vb
//! ' Class: ProcessLauncher
//! Private m_processes As Collection
//!
//! Private Type ProcessInfo
//!     TaskId As Double
//!     ProgramPath As String
//!     LaunchTime As Date
//!     Description As String
//! End Type
//!
//! Private Sub Class_Initialize()
//!     Set m_processes = New Collection
//! End Sub
//!
//! Public Function LaunchProcess(programPath As String, _
//!                               Optional description As String = "", _
//!                               Optional windowStyle As Integer = vbNormalFocus) As Double
//!     Dim taskId As Double
//!     Dim procInfo As ProcessInfo
//!     
//!     On Error GoTo ErrorHandler
//!     
//!     taskId = Shell(programPath, windowStyle)
//!     
//!     If taskId <> 0 Then
//!         procInfo.TaskId = taskId
//!         procInfo.ProgramPath = programPath
//!         procInfo.LaunchTime = Now
//!         procInfo.Description = description
//!         
//!         m_processes.Add procInfo, CStr(taskId)
//!     End If
//!     
//!     LaunchProcess = taskId
//!     Exit Function
//!     
//! ErrorHandler:
//!     LaunchProcess = 0
//! End Function
//!
//! Public Function ActivateProcess(taskId As Double) As Boolean
//!     On Error Resume Next
//!     AppActivate taskId
//!     ActivateProcess = (Err.Number = 0)
//! End Function
//!
//! Public Function GetProcessCount() As Long
//!     GetProcessCount = m_processes.Count
//! End Function
//!
//! Public Function GetProcessInfo(taskId As Double) As String
//!     Dim procInfo As ProcessInfo
//!     
//!     On Error Resume Next
//!     procInfo = m_processes(CStr(taskId))
//!     
//!     If Err.Number = 0 Then
//!         GetProcessInfo = "Program: " & procInfo.ProgramPath & vbCrLf & _
//!                         "Description: " & procInfo.Description & vbCrLf & _
//!                         "Launched: " & procInfo.LaunchTime & vbCrLf & _
//!                         "Task ID: " & procInfo.TaskId
//!     Else
//!         GetProcessInfo = "Process not found"
//!     End If
//! End Function
//!
//! Public Sub ClearProcesses()
//!     Set m_processes = New Collection
//! End Sub
//! ```
//!
//! ### Example 2: `CommandExecutor` Module
//! Execute command-line commands with output capture
//! ```vb
//! ' Module: CommandExecutor
//!
//! Public Function ExecuteCommandWithOutput(command As String, _
//!                                          ByRef output As String) As Boolean
//!     Dim tempFile As String
//!     Dim fileNum As Integer
//!     Dim commandLine As String
//!     Dim taskId As Double
//!     
//!     On Error GoTo ErrorHandler
//!     
//!     ' Create temp file for output
//!     tempFile = Environ("TEMP") & "\cmdout_" & Format(Now, "yyyymmddhhnnss") & ".txt"
//!     
//!     ' Redirect output to temp file
//!     commandLine = "cmd.exe /c " & command & " > """ & tempFile & """ 2>&1"
//!     
//!     taskId = Shell(commandLine, vbHide)
//!     If taskId = 0 Then
//!         ExecuteCommandWithOutput = False
//!         Exit Function
//!     End If
//!     
//!     ' Wait for command to complete (primitive wait)
//!     Sleep 1000  ' Would need to declare Sleep API
//!     
//!     ' Read output file
//!     fileNum = FreeFile
//!     Open tempFile For Input As #fileNum
//!     output = Input(LOF(fileNum), #fileNum)
//!     Close #fileNum
//!     
//!     ' Clean up
//!     Kill tempFile
//!     
//!     ExecuteCommandWithOutput = True
//!     Exit Function
//!     
//! ErrorHandler:
//!     If fileNum > 0 Then Close #fileNum
//!     On Error Resume Next
//!     If Dir(tempFile) <> "" Then Kill tempFile
//!     ExecuteCommandWithOutput = False
//! End Function
//!
//! Public Function RunCommandHidden(command As String) As Boolean
//!     Dim taskId As Double
//!     
//!     On Error Resume Next
//!     taskId = Shell("cmd.exe /c " & command, vbHide)
//!     RunCommandHidden = (taskId <> 0 And Err.Number = 0)
//! End Function
//!
//! Public Function RunCommandVisible(command As String) As Double
//!     On Error Resume Next
//!     RunCommandVisible = Shell("cmd.exe /k " & command, vbNormalFocus)
//! End Function
//! ```
//!
//! ### Example 3: `ApplicationLauncher` Class
//! Launch applications with comprehensive error handling
//! ```vb
//! ' Class: ApplicationLauncher
//! Private m_lastError As String
//! Private m_lastTaskId As Double
//!
//! Public Function LaunchApplication(programPath As String, _
//!                                   Optional arguments As String = "", _
//!                                   Optional windowStyle As Integer = vbNormalFocus, _
//!                                   Optional verifyExists As Boolean = True) As Boolean
//!     Dim fullCommand As String
//!     
//!     On Error GoTo ErrorHandler
//!     
//!     m_lastError = ""
//!     m_lastTaskId = 0
//!     
//!     ' Verify program exists
//!     If verifyExists Then
//!         If Dir(programPath) = "" Then
//!             m_lastError = "Program not found: " & programPath
//!             LaunchApplication = False
//!             Exit Function
//!         End If
//!     End If
//!     
//!     ' Build command line
//!     fullCommand = programPath
//!     If InStr(fullCommand, " ") > 0 And Left(fullCommand, 1) <> """" Then
//!         fullCommand = """" & fullCommand & """"
//!     End If
//!     
//!     If Len(arguments) > 0 Then
//!         fullCommand = fullCommand & " " & arguments
//!     End If
//!     
//!     ' Launch
//!     m_lastTaskId = Shell(fullCommand, windowStyle)
//!     
//!     If m_lastTaskId = 0 Then
//!         m_lastError = "Shell function returned 0"
//!         LaunchApplication = False
//!     Else
//!         LaunchApplication = True
//!     End If
//!     
//!     Exit Function
//!     
//! ErrorHandler:
//!     m_lastError = "Error " & Err.Number & ": " & Err.Description
//!     LaunchApplication = False
//! End Function
//!
//! Public Function LaunchAndActivate(programPath As String, _
//!                                   Optional arguments As String = "") As Boolean
//!     Dim success As Boolean
//!     Dim attempts As Integer
//!     
//!     success = LaunchApplication(programPath, arguments, vbNormalFocus)
//!     
//!     If Not success Then
//!         LaunchAndActivate = False
//!         Exit Function
//!     End If
//!     
//!     ' Try to activate
//!     For attempts = 1 To 20
//!         DoEvents
//!         On Error Resume Next
//!         AppActivate m_lastTaskId
//!         If Err.Number = 0 Then
//!             LaunchAndActivate = True
//!             Exit Function
//!         End If
//!         Err.Clear
//!     Next attempts
//!     
//!     LaunchAndActivate = False
//! End Function
//!
//! Public Property Get LastError() As String
//!     LastError = m_lastError
//! End Property
//!
//! Public Property Get LastTaskId() As Double
//!     LastTaskId = m_lastTaskId
//! End Property
//!
//! Public Function OpenFileWithDefaultApp(filePath As String) As Boolean
//!     Dim commandLine As String
//!     
//!     ' Use Windows "start" command
//!     commandLine = "cmd.exe /c start """" """ & filePath & """"
//!     
//!     On Error Resume Next
//!     m_lastTaskId = Shell(commandLine, vbHide)
//!     
//!     OpenFileWithDefaultApp = (m_lastTaskId <> 0 And Err.Number = 0)
//!     
//!     If Not OpenFileWithDefaultApp Then
//!         m_lastError = "Failed to open file: " & Err.Description
//!     End If
//! End Function
//! ```
//!
//! ### Example 4: `BatchFileRunner` Module
//! Execute batch files with enhanced functionality
//! ```vb
//! ' Module: BatchFileRunner
//!
//! Public Function ExecuteBatchFile(batchPath As String, _
//!                                  Optional parameters As String = "", _
//!                                  Optional visible As Boolean = False, _
//!                                  Optional workingDir As String = "") As Double
//!     Dim commandLine As String
//!     Dim windowStyle As Integer
//!     Dim originalDir As String
//!     
//!     On Error GoTo ErrorHandler
//!     
//!     ' Verify batch file exists
//!     If Dir(batchPath) = "" Then
//!         MsgBox "Batch file not found: " & batchPath, vbExclamation
//!         ExecuteBatchFile = 0
//!         Exit Function
//!     End If
//!     
//!     ' Quote path if needed
//!     If InStr(batchPath, " ") > 0 Then
//!         commandLine = """" & batchPath & """"
//!     Else
//!         commandLine = batchPath
//!     End If
//!     
//!     ' Add parameters
//!     If Len(parameters) > 0 Then
//!         commandLine = commandLine & " " & parameters
//!     End If
//!     
//!     ' Change working directory if specified
//!     If Len(workingDir) > 0 Then
//!         originalDir = CurDir
//!         ChDir workingDir
//!     End If
//!     
//!     ' Execute
//!     windowStyle = IIf(visible, vbNormalFocus, vbHide)
//!     ExecuteBatchFile = Shell(commandLine, windowStyle)
//!     
//!     ' Restore directory
//!     If Len(workingDir) > 0 Then
//!         ChDir originalDir
//!     End If
//!     
//!     Exit Function
//!     
//! ErrorHandler:
//!     If Len(workingDir) > 0 Then
//!         On Error Resume Next
//!         ChDir originalDir
//!     End If
//!     ExecuteBatchFile = 0
//! End Function
//!
//! Public Function RunBatchWithLog(batchPath As String, logPath As String) As Boolean
//!     Dim commandLine As String
//!     Dim taskId As Double
//!     
//!     ' Quote paths
//!     If InStr(batchPath, " ") > 0 Then batchPath = """" & batchPath & """"
//!     If InStr(logPath, " ") > 0 Then logPath = """" & logPath & """"
//!     
//!     ' Redirect output to log
//!     commandLine = "cmd.exe /c " & batchPath & " > " & logPath & " 2>&1"
//!     
//!     On Error Resume Next
//!     taskId = Shell(commandLine, vbHide)
//!     
//!     RunBatchWithLog = (taskId <> 0 And Err.Number = 0)
//! End Function
//!
//! Public Function CreateAndRunBatch(commands() As String, _
//!                                   Optional visible As Boolean = False) As Boolean
//!     Dim batchPath As String
//!     Dim fileNum As Integer
//!     Dim i As Long
//!     Dim taskId As Double
//!     
//!     On Error GoTo ErrorHandler
//!     
//!     ' Create temp batch file
//!     batchPath = Environ("TEMP") & "\temp_" & Format(Now, "yyyymmddhhnnss") & ".bat"
//!     
//!     ' Write commands
//!     fileNum = FreeFile
//!     Open batchPath For Output As #fileNum
//!     Print #fileNum, "@echo off"
//!     For i = LBound(commands) To UBound(commands)
//!         Print #fileNum, commands(i)
//!     Next i
//!     Close #fileNum
//!     
//!     ' Execute
//!     taskId = Shell(batchPath, IIf(visible, vbNormalFocus, vbHide))
//!     
//!     CreateAndRunBatch = (taskId <> 0)
//!     Exit Function
//!     
//! ErrorHandler:
//!     If fileNum > 0 Then Close #fileNum
//!     CreateAndRunBatch = False
//! End Function
//! ```
//!
//! ## Error Handling
//!
//! The Shell function can generate the following errors:
//!
//! - **Error 5** (Invalid procedure call or argument): Invalid windowstyle parameter
//! - **Error 53** (File not found): Program or path not found
//! - **Error 76** (Path not found): Directory in path doesn't exist
//!
//! Always use error handling when executing external programs:
//! ```vb
//! On Error Resume Next
//! taskId = Shell(programPath, vbNormalFocus)
//! If Err.Number <> 0 Or taskId = 0 Then
//!     MsgBox "Error: " & Err.Description
//! End If
//! ```
//!
//! ## Performance Considerations
//!
//! - Shell executes asynchronously and returns immediately
//! - No performance impact on VB6 app after launch
//! - Multiple programs can be launched simultaneously
//! - Task ID allows tracking and activation
//! - Consider resource usage when launching many programs
//! - Use `DoEvents` to allow UI updates after Shell
//!
//! ## Best Practices
//!
//! 1. **Error Handling**: Always wrap Shell in error handling
//! 2. **Path Quoting**: Quote paths with spaces using double quotes
//! 3. **Verify Existence**: Check file exists before shelling (Dir function)
//! 4. **Security**: Validate user input to prevent command injection
//! 5. **Resource Management**: Track launched processes
//! 6. **Window Style**: Choose appropriate window style for user experience
//! 7. **Wait Strategy**: Use `AppActivate` or API for synchronization if needed
//! 8. **Return Value**: Check return value (0 = failure)
//! 9. **Documentation**: Document external dependencies
//! 10. **Testing**: Test with various paths and edge cases
//!
//! ## Comparison with Related Functions
//!
//! | Method | Purpose | Wait for Completion | Capture Output | Platform |
//! |--------|---------|---------------------|----------------|----------|
//! | Shell | Execute program | No (async) | No | VB6/VBA |
//! | `CreateProcess` API | Execute program | Optional | Optional | Windows API |
//! | WScript.Shell.Run | Execute program | Optional | No | WSH |
//! | Exec method | Execute program | No | Yes | WSH |
//! | `ShellExecute` API | Execute/open files | No | No | Windows API |
//!
//! ## Platform Considerations
//!
//! - Available in VB6, VBA (Windows only)
//! - Windows-specific function
//! - Task ID is Windows-specific process identifier
//! - Path separators are backslashes (\)
//! - Case-insensitive on Windows
//! - Long filename support (use quotes)
//! - Windows versions may affect behavior
//!
//! ## Limitations
//!
//! - No built-in way to wait for completion
//! - Cannot capture standard output/error directly
//! - Limited to Windows operating system
//! - Task ID becomes invalid when process terminates
//! - No parent-child process relationship tracking
//! - Cannot pass structured data to launched program
//! - Security risks with user-supplied paths
//! - No control over process priority or environment
//!
//! ## Related Functions
//!
//! - `AppActivate`: Activates a running application window by task ID
//! - `CreateObject`: Creates automation objects for inter-app communication
//! - `SendKeys`: Sends keystrokes to active window
//! - `Dir`: Verifies file existence before shelling
//! - `Environ`: Gets environment variables for path construction
//!
#[cfg(test)]
mod tests {
    use crate::*;

    #[test]
    fn shell_basic() {
        let source = r#"
Sub Test()
    Dim taskId As Double
    taskId = Shell("notepad.exe")
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_with_window_style() {
        let source = r#"
Sub Test()
    Dim result As Double
    result = Shell("calc.exe", vbNormalFocus)
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_if_statement() {
        let source = r#"
Sub Test()
    If Shell("notepad.exe", vbNormalFocus) = 0 Then
        MsgBox "Failed"
    End If
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_function_return() {
        let source = r#"
Function LaunchApp() As Double
    LaunchApp = Shell("notepad.exe", vbNormalFocus)
End Function
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_variable_assignment() {
        let source = r"
Sub Test()
    Dim procId As Double
    procId = Shell(programPath, vbMaximizedFocus)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_msgbox() {
        let source = r#"
Sub Test()
    MsgBox "Task ID: " & Shell("calc.exe", vbNormalFocus)
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_debug_print() {
        let source = r#"
Sub Test()
    Debug.Print Shell("notepad.exe", vbHide)
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_select_case() {
        let source = r#"
Sub Test()
    Select Case Shell(appPath, vbNormalFocus)
        Case 0
            MsgBox "Failed"
        Case Else
            MsgBox "Success"
    End Select
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_class_usage() {
        let source = r"
Class AppLauncher
    Public Function Launch(path As String) As Double
        Launch = Shell(path, vbNormalFocus)
    End Function
End Class
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_with_statement() {
        let source = r#"
Sub Test()
    With AppLauncher
        Dim id As Double
        id = Shell("notepad.exe", vbNormalFocus)
    End With
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_elseif() {
        let source = r#"
Sub Test()
    Dim t As Double
    t = Shell(path, vbNormalFocus)
    If t = 0 Then
        MsgBox "Failed"
    ElseIf t > 0 Then
        MsgBox "Success"
    End If
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_for_loop() {
        let source = r#"
Sub Test()
    Dim i As Integer
    For i = 1 To 3
        Shell "notepad.exe", vbNormalFocus
    Next i
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_do_while() {
        let source = r"
Sub Test()
    Do While Shell(program, vbHide) <> 0
        Exit Do
    Loop
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_do_until() {
        let source = r"
Sub Test()
    Do Until Shell(cmd, vbNormalFocus) > 0
        DoEvents
    Loop
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_while_wend() {
        let source = r"
Sub Test()
    While retries < 3
        Shell program, vbNormalFocus
        retries = retries + 1
    Wend
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_parentheses() {
        let source = r#"
Sub Test()
    Dim result As Double
    result = (Shell("notepad.exe", vbNormalFocus))
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_iif() {
        let source = r#"
Sub Test()
    Dim msg As String
    msg = IIf(Shell("calc.exe", vbHide) > 0, "OK", "Failed")
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_array_assignment() {
        let source = r#"
Sub Test()
    Dim tasks(5) As Double
    tasks(0) = Shell("notepad.exe", vbNormalFocus)
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_property_assignment() {
        let source = r#"
Class Process
    Public TaskId As Double
End Class

Sub Test()
    Dim p As New Process
    p.TaskId = Shell("calc.exe", vbNormalFocus)
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_function_argument() {
        let source = r#"
Sub ProcessTask(taskId As Double)
End Sub

Sub Test()
    ProcessTask Shell("notepad.exe", vbNormalFocus)
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_concatenation() {
        let source = r#"
Sub Test()
    Dim msg As String
    msg = "Task: " & Shell("calc.exe", vbNormalFocus)
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_comparison() {
        let source = r"
Sub Test()
    Dim success As Boolean
    success = (Shell(path, vbNormalFocus) > 0)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_with_arguments() {
        let source = r#"
Sub Test()
    Dim t As Double
    t = Shell("notepad.exe C:\file.txt", vbNormalFocus)
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_quoted_path() {
        let source = r"
Sub Test()
    Dim id As Double
    id = Shell(Chr(34) & path & Chr(34), vbNormalFocus)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_error_handling() {
        let source = r#"
Sub Test()
    On Error Resume Next
    Dim t As Double
    t = Shell(programPath, vbNormalFocus)
    If Err.Number <> 0 Then
        MsgBox "Error"
    End If
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_on_error_goto() {
        let source = r#"
Sub Test()
    On Error GoTo ErrorHandler
    Dim taskId As Double
    taskId = Shell("C:\app.exe", vbNormalFocus)
    Exit Sub
ErrorHandler:
    MsgBox "Error launching app"
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn shell_cmd_exe() {
        let source = r#"
Sub Test()
    Dim cmdTaskId As Double
    cmdTaskId = Shell("cmd.exe /c dir", vbHide)
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path(
            "../../../../../snapshots/syntax/library/functions/interaction/shell",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}