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
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
//! # `FormatCurrency` Function
//!
//! Returns an expression formatted as a currency value using the currency symbol defined in the system control panel.
//!
//! ## Syntax
//!
//! ```vb
//! FormatCurrency(expression[, numdigitsafterdecimal[, includeleadingdigit[, useparensfornegativenumbers[, groupdigits]]]])
//! ```
//!
//! ## Parameters
//!
//! - **expression**: Required. Expression to be formatted.
//! - **numdigitsafterdecimal**: Optional. Numeric value indicating how many places to the right of the decimal are displayed. Default is -1, which indicates the computer's regional settings are used.
//! - **includeleadingdigit**: Optional. Tristate constant that indicates whether a leading zero is displayed for fractional values. See Settings for values.
//! - **useparensfornegativenumbers**: Optional. Tristate constant that indicates whether to place negative values within parentheses. See Settings for values.
//! - **groupdigits**: Optional. Tristate constant that indicates whether numbers are grouped using the group delimiter specified in the computer's regional settings. See Settings for values.
//!
//! ## Settings
//!
//! The includeleadingdigit, useparensfornegativenumbers, and groupdigits arguments have the following settings:
//!
//! - **vbTrue** (-1): True
//! - **vbFalse** (0): False
//! - **vbUseDefault** (-2): Use the setting from the computer's regional settings
//!
//! ## Return Value
//!
//! Returns a `Variant` of subtype `String` containing the expression formatted as a currency value.
//!
//! ## Remarks
//!
//! The `FormatCurrency` function provides a simple way to format numbers as currency values
//! using the system's locale settings. It automatically applies the currency symbol, decimal
//! separator, thousand separator, and negative number formatting according to regional settings.
//!
//! **Important Characteristics:**
//!
//! - Uses system locale for currency symbol and formatting
//! - Default: 2 decimal places (from regional settings)
//! - Automatically adds thousand separators
//! - Negative numbers can be displayed with parentheses or minus sign
//! - Leading zeros controlled by regional settings or parameter
//! - Currency symbol position depends on locale (before or after amount)
//! - Returns empty string if expression is Null
//! - More convenient than `Format` for simple currency formatting
//! - Less flexible than `Format` for custom patterns
//! - Locale-aware (respects user's regional settings)
//!
//! ## Typical Uses
//!
//! - Display prices and monetary amounts
//! - Format financial reports
//! - Show invoice totals
//! - Display account balances
//! - Format transaction amounts
//! - Create currency-formatted exports
//! - Display budget figures
//! - Show cost calculations
//!
//! ## Examples
//!
//! ### Basic Usage
//!
//! ```vb
//! Dim amount As Double
//! amount = 1234.567
//!
//! ' Default formatting (2 decimal places, system settings)
//! Debug.Print FormatCurrency(amount)           ' $1,234.57
//!
//! ' No decimal places
//! Debug.Print FormatCurrency(amount, 0)        ' $1,235
//!
//! ' Three decimal places
//! Debug.Print FormatCurrency(amount, 3)        ' $1,234.567
//!
//! ' Negative with parentheses
//! Debug.Print FormatCurrency(-500, , , vbTrue) ' ($500.00)
//! ```
//!
//! ### Handling Negative Values
//!
//! ```vb
//! Dim balance As Double
//! balance = -1250.50
//!
//! ' Default negative (with minus sign)
//! Debug.Print FormatCurrency(balance)          ' -$1,250.50
//!
//! ' Parentheses for negative
//! Debug.Print FormatCurrency(balance, 2, , vbTrue)  ' ($1,250.50)
//!
//! ' No parentheses (explicit)
//! Debug.Print FormatCurrency(balance, 2, , vbFalse) ' -$1,250.50
//! ```
//!
//! ### Control Leading Digits
//!
//! ```vb
//! Dim fraction As Double
//! fraction = 0.75
//!
//! ' With leading zero (default)
//! Debug.Print FormatCurrency(fraction)         ' $0.75
//!
//! ' No leading zero
//! Debug.Print FormatCurrency(fraction, 2, vbFalse)  ' $.75
//!
//! ' Explicit leading zero
//! Debug.Print FormatCurrency(fraction, 2, vbTrue)   ' $0.75
//! ```
//!
//! ## Common Patterns
//!
//! ### Format Invoice Line Items
//!
//! ```vb
//! Sub DisplayInvoiceLines(items As Collection)
//!     Dim item As Variant
//!     Dim total As Double
//!     
//!     Debug.Print "Item", "Quantity", "Price", "Amount"
//!     Debug.Print String(60, "-")
//!     
//!     total = 0
//!     For Each item In items
//!         Debug.Print item.Name, _
//!                     item.Quantity, _
//!                     FormatCurrency(item.Price), _
//!                     FormatCurrency(item.Quantity * item.Price)
//!         total = total + (item.Quantity * item.Price)
//!     Next item
//!     
//!     Debug.Print String(60, "-")
//!     Debug.Print "Total:", , , FormatCurrency(total)
//! End Sub
//! ```
//!
//! ### Format Account Balance with Parentheses
//!
//! ```vb
//! Function FormatAccountBalance(balance As Double) As String
//!     ' Show negative balances in parentheses (accounting style)
//!     FormatAccountBalance = FormatCurrency(balance, 2, vbTrue, vbTrue, vbTrue)
//! End Function
//!
//! ' Usage
//! Debug.Print FormatAccountBalance(1500)       ' $1,500.00
//! Debug.Print FormatAccountBalance(-250.50)    ' ($250.50)
//! ```
//!
//! ### Create Price Display
//!
//! ```vb
//! Function FormatPrice(price As Double, showCents As Boolean) As String
//!     If showCents Then
//!         FormatPrice = FormatCurrency(price, 2)
//!     Else
//!         FormatPrice = FormatCurrency(price, 0)
//!     End If
//! End Function
//!
//! ' Usage
//! Debug.Print FormatPrice(19.99, True)         ' $19.99
//! Debug.Print FormatPrice(19.99, False)        ' $20
//! ```
//!
//! ### Display Transaction Summary
//!
//! ```vb
//! Sub ShowTransactionSummary(credits As Double, debits As Double)
//!     Dim balance As Double
//!     
//!     Debug.Print "Transaction Summary"
//!     Debug.Print String(40, "=")
//!     Debug.Print "Credits:  ", FormatCurrency(credits)
//!     Debug.Print "Debits:   ", FormatCurrency(debits, 2, , vbTrue)
//!     Debug.Print String(40, "-")
//!     
//!     balance = credits - debits
//!     Debug.Print "Balance:  ", FormatCurrency(balance, 2, , vbTrue)
//! End Sub
//! ```
//!
//! ### Format Budget Report
//!
//! ```vb
//! Sub PrintBudgetReport()
//!     Dim budgeted As Double
//!     Dim actual As Double
//!     Dim variance As Double
//!     
//!     budgeted = 50000
//!     actual = 48500
//!     variance = actual - budgeted
//!     
//!     Debug.Print "Budget Report"
//!     Debug.Print String(50, "=")
//!     Debug.Print "Budgeted:", FormatCurrency(budgeted, 0)
//!     Debug.Print "Actual:  ", FormatCurrency(actual, 0)
//!     Debug.Print "Variance:", FormatCurrency(variance, 0, , vbTrue)
//!     
//!     If variance < 0 Then
//!         Debug.Print "Status: Under budget"
//!     Else
//!         Debug.Print "Status: Over budget"
//!     End If
//! End Sub
//! ```
//!
//! ### `ListBox`/`ComboBox` Population
//!
//! ```vb
//! Sub PopulatePriceList(lstPrices As ListBox, prices() As Double)
//!     Dim i As Long
//!     
//!     lstPrices.Clear
//!     
//!     For i = LBound(prices) To UBound(prices)
//!         lstPrices.AddItem FormatCurrency(prices(i))
//!     Next i
//! End Sub
//! ```
//!
//! ### Format for Database Display
//!
//! ```vb
//! Function GetFormattedPrice(rs As ADODB.Recordset, fieldName As String) As String
//!     If IsNull(rs.Fields(fieldName).Value) Then
//!         GetFormattedPrice = "N/A"
//!     Else
//!         GetFormattedPrice = FormatCurrency(rs.Fields(fieldName).Value)
//!     End If
//! End Function
//! ```
//!
//! ### Calculate and Display Tax
//!
//! ```vb
//! Function DisplayPriceWithTax(basePrice As Double, taxRate As Double) As String
//!     Dim tax As Double
//!     Dim total As Double
//!     
//!     tax = basePrice * taxRate
//!     total = basePrice + tax
//!     
//!     DisplayPriceWithTax = "Price: " & FormatCurrency(basePrice) & vbCrLf & _
//!                           "Tax: " & FormatCurrency(tax) & vbCrLf & _
//!                           "Total: " & FormatCurrency(total)
//! End Function
//!
//! ' Usage
//! MsgBox DisplayPriceWithTax(100, 0.08)
//! ```
//!
//! ### Format Payment Schedule
//!
//! ```vb
//! Sub ShowPaymentSchedule(loanAmount As Double, months As Integer, rate As Double)
//!     Dim payment As Double
//!     Dim i As Integer
//!     Dim balance As Double
//!     
//!     payment = loanAmount / months
//!     balance = loanAmount
//!     
//!     Debug.Print "Payment Schedule"
//!     Debug.Print String(50, "=")
//!     Debug.Print "Month", "Payment", "Balance"
//!     Debug.Print String(50, "-")
//!     
//!     For i = 1 To months
//!         Debug.Print i, FormatCurrency(payment), FormatCurrency(balance)
//!         balance = balance - payment
//!     Next i
//! End Sub
//! ```
//!
//! ### Compare Values
//!
//! ```vb
//! Function ComparePrices(price1 As Double, price2 As Double) As String
//!     Dim difference As Double
//!     difference = price1 - price2
//!     
//!     ComparePrices = FormatCurrency(price1) & " vs " & FormatCurrency(price2) & _
//!                     " (Difference: " & FormatCurrency(difference, 2, , vbTrue) & ")"
//! End Function
//! ```
//!
//! ### Shopping Cart Total
//!
//! ```vb
//! Function GetCartSummary(items As Collection) As String
//!     Dim item As Variant
//!     Dim subtotal As Double
//!     Dim tax As Double
//!     Dim shipping As Double
//!     Dim total As Double
//!     
//!     subtotal = 0
//!     For Each item In items
//!         subtotal = subtotal + (item.Price * item.Quantity)
//!     Next item
//!     
//!     tax = subtotal * 0.08
//!     shipping = 5.99
//!     total = subtotal + tax + shipping
//!     
//!     GetCartSummary = "Subtotal: " & FormatCurrency(subtotal) & vbCrLf & _
//!                      "Tax:      " & FormatCurrency(tax) & vbCrLf & _
//!                      "Shipping: " & FormatCurrency(shipping) & vbCrLf & _
//!                      "Total:    " & FormatCurrency(total)
//! End Function
//! ```
//!
//! ## Advanced Usage
//!
//! ### Flexible Currency Formatter
//!
//! ```vb
//! Function FormatCurrencyEx(amount As Double, _
//!                           Optional decimals As Integer = 2, _
//!                           Optional useParens As Boolean = True, _
//!                           Optional useGroups As Boolean = True) As String
//!     Dim leadingDigit As VbTriState
//!     Dim parens As VbTriState
//!     Dim groups As VbTriState
//!     
//!     leadingDigit = vbTrue
//!     parens = IIf(useParens, vbTrue, vbFalse)
//!     groups = IIf(useGroups, vbTrue, vbFalse)
//!     
//!     FormatCurrencyEx = FormatCurrency(amount, decimals, leadingDigit, parens, groups)
//! End Function
//! ```
//!
//! ### Multi-Currency Support
//!
//! ```vb
//! Function FormatMultiCurrency(amount As Double, currencyCode As String) As String
//!     ' Simple multi-currency display (uses FormatCurrency then replaces symbol)
//!     Dim formatted As String
//!     formatted = FormatCurrency(amount)
//!     
//!     Select Case UCase(currencyCode)
//!         Case "USD"
//!             ' Keep default $ symbol
//!             FormatMultiCurrency = formatted
//!         Case "EUR"
//!             FormatMultiCurrency = Replace(formatted, "$", "€")
//!         Case "GBP"
//!             FormatMultiCurrency = Replace(formatted, "$", "£")
//!         Case "JPY"
//!             FormatMultiCurrency = Replace(formatted, "$", "Â¥")
//!             FormatMultiCurrency = Replace(FormatMultiCurrency, ".00", "")
//!         Case Else
//!             FormatMultiCurrency = currencyCode & " " & Format(amount, "#,##0.00")
//!     End Select
//! End Function
//! ```
//!
//! ### Financial Statement Formatter
//!
//! ```vb
//! Type FinancialLine
//!     Description As String
//!     Amount As Double
//!     IsSubtotal As Boolean
//! End Type
//!
//! Function FormatFinancialStatement(lines() As FinancialLine) As String
//!     Dim result As String
//!     Dim i As Long
//!     Dim line As String
//!     
//!     result = "Financial Statement" & vbCrLf
//!     result = result & String(60, "=") & vbCrLf
//!     
//!     For i = LBound(lines) To UBound(lines)
//!         line = lines(i).Description
//!         
//!         ' Right-align amounts
//!         line = line & Space(40 - Len(line))
//!         line = line & FormatCurrency(lines(i).Amount, 2, vbTrue, vbTrue, vbTrue)
//!         
//!         If lines(i).IsSubtotal Then
//!             result = result & String(60, "-") & vbCrLf
//!         End If
//!         
//!         result = result & line & vbCrLf
//!     Next i
//!     
//!     FormatFinancialStatement = result
//! End Function
//! ```
//!
//! ### Dynamic Precision Formatter
//!
//! ```vb
//! Function FormatCurrencyDynamic(amount As Double) As String
//!     ' Use different precision based on amount magnitude
//!     If Abs(amount) >= 1000000 Then
//!         ' Millions: no decimals
//!         FormatCurrencyDynamic = FormatCurrency(amount, 0) & "M"
//!     ElseIf Abs(amount) >= 1000 Then
//!         ' Thousands: no decimals
//!         FormatCurrencyDynamic = FormatCurrency(amount, 0)
//!     ElseIf Abs(amount) >= 1 Then
//!         ' Regular: 2 decimals
//!         FormatCurrencyDynamic = FormatCurrency(amount, 2)
//!     Else
//!         ' Small amounts: 4 decimals
//!         FormatCurrencyDynamic = FormatCurrency(amount, 4)
//!     End If
//! End Function
//! ```
//!
//! ### Conditional Formatting
//!
//! ```vb
//! Function FormatProfitLoss(amount As Double) As String
//!     ' Format with color indicators for profit/loss
//!     If amount > 0 Then
//!         FormatProfitLoss = "[GREEN]+" & FormatCurrency(amount)
//!     ElseIf amount < 0 Then
//!         FormatProfitLoss = "[RED]" & FormatCurrency(amount, 2, , vbTrue)
//!     Else
//!         FormatProfitLoss = "[BLACK]" & FormatCurrency(0)
//!     End If
//! End Function
//! ```
//!
//! ### Grid/Report Alignment
//!
//! ```vb
//! Function FormatCurrencyAligned(amount As Double, width As Integer) As String
//!     Dim formatted As String
//!     formatted = FormatCurrency(amount, 2, vbTrue, vbTrue, vbTrue)
//!     
//!     ' Right-align in field
//!     If Len(formatted) < width Then
//!         FormatCurrencyAligned = Space(width - Len(formatted)) & formatted
//!     Else
//!         FormatCurrencyAligned = formatted
//!     End If
//! End Function
//! ```
//!
//! ## Error Handling
//!
//! ```vb
//! Function SafeFormatCurrency(value As Variant, _
//!                             Optional decimals As Integer = 2) As String
//!     On Error GoTo ErrorHandler
//!     
//!     If IsNull(value) Then
//!         SafeFormatCurrency = "N/A"
//!     ElseIf Not IsNumeric(value) Then
//!         SafeFormatCurrency = "Invalid"
//!     Else
//!         SafeFormatCurrency = FormatCurrency(CDbl(value), decimals)
//!     End If
//!     
//!     Exit Function
//!     
//! ErrorHandler:
//!     Select Case Err.Number
//!         Case 13  ' Type mismatch
//!             SafeFormatCurrency = "Type Error"
//!         Case 6   ' Overflow
//!             SafeFormatCurrency = "Overflow"
//!         Case Else
//!             SafeFormatCurrency = "Error"
//!     End Select
//! End Function
//! ```
//!
//! ### Common Errors
//!
//! - **Error 13** (Type Mismatch): Expression cannot be converted to numeric
//! - **Error 6** (Overflow): Value too large for `Double`
//! - **Error 5** (Invalid procedure call): Invalid decimal places parameter
//!
//! ## Performance Considerations
//!
//! - `FormatCurrency` is fast for simple formatting
//! - Slightly slower than `Format` for custom patterns
//! - Faster than building format strings manually
//! - Locale lookups cached by system
//! - Avoid repeated calls in tight loops if possible
//! - Consider caching formatted values for display
//!
//! ## Best Practices
//!
//! ### Use `FormatCurrency` for User-Facing Amounts
//!
//! ```vb
//! ' Good - Locale-aware, user-friendly
//! lblPrice.Caption = FormatCurrency(price)
//!
//! ' Less portable - Hard-coded format
//! lblPrice.Caption = "$" & Format(price, "0.00")
//! ```
//!
//! ### Handle `Null` Values
//!
//! ```vb
//! ' Good - Check for Null
//! If Not IsNull(amount) Then
//!     formatted = FormatCurrency(amount)
//! Else
//!     formatted = "N/A"
//! End If
//! ```
//!
//! ### Be Consistent with Negative Formatting
//!
//! ```vb
//! ' Good - Use same style throughout application
//! Const USE_PARENS = vbTrue
//! formatted = FormatCurrency(balance, 2, , USE_PARENS)
//! ```
//!
//! ## Comparison with Other Functions
//!
//! ### `FormatCurrency` vs `Format`
//!
//! ```vb
//! ' FormatCurrency - Simple, locale-aware
//! result = FormatCurrency(1234.56)
//!
//! ' Format - More control, custom patterns
//! result = Format(1234.56, "$#,##0.00")
//! ```
//!
//! ### `FormatCurrency` vs `FormatNumber`
//!
//! ```vb
//! ' FormatCurrency - Adds currency symbol
//! result = FormatCurrency(1234.56)        ' $1,234.56
//!
//! ' FormatNumber - No currency symbol
//! result = FormatNumber(1234.56)          ' 1,234.56
//! ```
//!
//! ### `FormatCurrency` vs `Str`/`CStr`
//!
//! ```vb
//! ' FormatCurrency - Full formatting
//! result = FormatCurrency(1234.56)        ' $1,234.56
//!
//! ' Str - Basic conversion, no formatting
//! result = Str(1234.56)                   ' " 1234.56"
//!
//! ' CStr - Basic conversion
//! result = CStr(1234.56)                  ' "1234.56"
//! ```
//!
//! ## Limitations
//!
//! - Uses system locale (cannot specify different locale)
//! - Limited to system's currency symbol
//! - Cannot customize symbol position
//! - All parameters optional, making errors less obvious
//! - Tristate parameters can be confusing
//! - No built-in rounding mode control
//! - Cannot format multiple currencies in same session
//!
//! ## Regional Settings Impact
//!
//! The `FormatCurrency` function behavior varies by locale:
//!
//! - **United States**: $1,234.56
//! - **United Kingdom**: £1,234.56
//! - **European Union**: €1.234,56 (note decimal/thousand separators)
//! - **Japan**: ¥1,235 (typically no decimal places)
//!
//! ## Related Functions
//!
//! - `Format`: More flexible formatting with custom patterns
//! - `FormatNumber`: Format numbers without currency symbol
//! - `FormatPercent`: Format numbers as percentages
//! - `FormatDateTime`: Format date/time values
//! - `CCur`: Convert expression to `Currency` type
//! - `CDbl`: Convert expression to `Double` type

#[cfg(test)]
mod tests {
    use crate::*;

    #[test]
    fn formatcurrency_basic() {
        let source = r"
result = FormatCurrency(amount)
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_decimals() {
        let source = r"
formatted = FormatCurrency(value, 2)
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_no_decimals() {
        let source = r"
formatted = FormatCurrency(amount, 0)
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_parens() {
        let source = r"
result = FormatCurrency(balance, 2, , vbTrue)
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_all_params() {
        let source = r"
formatted = FormatCurrency(amount, 2, vbTrue, vbTrue, vbTrue)
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_debug_print() {
        let source = r"
Debug.Print FormatCurrency(price)
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_concatenation() {
        let source = r#"
msg = "Total: " & FormatCurrency(total)
"#;
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_in_function() {
        let source = r"
Function FormatAccountBalance(balance As Double) As String
    FormatAccountBalance = FormatCurrency(balance, 2, vbTrue, vbTrue, vbTrue)
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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_if_statement() {
        let source = r"
If showCents Then
    result = FormatCurrency(price, 2)
Else
    result = FormatCurrency(price, 0)
End If
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_listbox() {
        let source = r"
lstPrices.AddItem FormatCurrency(prices(i))
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_multiline() {
        let source = r#"
summary = "Subtotal: " & FormatCurrency(subtotal) & vbCrLf & _
          "Tax: " & FormatCurrency(tax) & vbCrLf & _
          "Total: " & FormatCurrency(total)
"#;
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_calculation() {
        let source = r"
result = FormatCurrency(price * quantity)
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_isnull_check() {
        let source = r"
If Not IsNull(amount) Then
    formatted = FormatCurrency(amount)
End If
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_comparison() {
        let source = r#"
comparison = FormatCurrency(price1) & " vs " & FormatCurrency(price2)
"#;
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_error_handling() {
        let source = r#"
On Error GoTo ErrorHandler
formatted = FormatCurrency(value, decimals)
Exit Function
ErrorHandler:
    formatted = "N/A"
"#;
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_for_loop() {
        let source = r"
For i = 1 To itemCount
    Debug.Print FormatCurrency(amounts(i))
Next i
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_select_case() {
        let source = r"
Select Case amount
    Case Is > 1000
        result = FormatCurrency(amount, 0)
    Case Else
        result = FormatCurrency(amount, 2)
End Select
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_msgbox() {
        let source = r#"
MsgBox "Total: " & FormatCurrency(total)
"#;
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_label_caption() {
        let source = r"
lblPrice.Caption = FormatCurrency(price)
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_recordset() {
        let source = r#"
formatted = FormatCurrency(rs.Fields("Amount").Value)
"#;
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_vbfalse() {
        let source = r"
result = FormatCurrency(fraction, 2, vbFalse)
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_negative() {
        let source = r"
formatted = FormatCurrency(balance, 2, , vbFalse)
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_subtraction() {
        let source = r"
difference = FormatCurrency(price1 - price2, 2, , vbTrue)
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_addition() {
        let source = r"
total = FormatCurrency(subtotal + tax + shipping)
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_with_cdbl() {
        let source = r"
result = FormatCurrency(CDbl(value), decimals)
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn formatcurrency_iif() {
        let source = r"
parens = IIf(useParens, vbTrue, vbFalse)
result = FormatCurrency(amount, 2, vbTrue, parens, vbTrue)
";
        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/string/formatcurrency",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}