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
//! # Sqr Function
//!
//! Returns a Double specifying the square root of a number.
//!
//! ## Syntax
//!
//! ```vb
//! Sqr(number)
//! ```
//!
//! ## Parameters
//!
//! - `number` - Required. Double or any valid numeric expression greater than or equal to 0.
//!
//! ## Return Value
//!
//! Returns a Double containing the square root of the number.
//!
//! ## Remarks
//!
//! The Sqr function calculates the positive square root of a non-negative number. It's one of the fundamental mathematical functions in VB6 and is commonly used in geometric calculations, statistical analysis, and scientific applications.
//!
//! Key characteristics:
//! - Returns the positive (principal) square root only
//! - Argument must be >= 0 (negative values cause Error 5)
//! - Returns Double for maximum precision
//! - Sqr(0) = 0
//! - Sqr(1) = 1
//! - Sqr(x) * Sqr(x) = x (within floating-point precision)
//! - Inverse operation of squaring: Sqr(x^2) = x (for x >= 0)
//!
//! Mathematical relationships:
//! - Sqr(x * y) = Sqr(x) * Sqr(y)
//! - Sqr(x / y) = Sqr(x) / Sqr(y)
//! - Sqr(x^2) = Abs(x)
//! - x^(1/2) = Sqr(x)
//! - x^(1/n) can be calculated as x^(1/n) = Exp(Log(x) / n)
//!
//! ## Typical Uses
//!
//! 1. **Distance Calculations**: Calculate distance between two points
//! 2. **Pythagorean Theorem**: Find hypotenuse or sides of right triangles
//! 3. **Standard Deviation**: Statistical calculations
//! 4. **Quadratic Equations**: Solve equations using quadratic formula
//! 5. **Normalization**: Normalize vectors and values
//! 6. **Root Mean Square**: Calculate RMS values
//! 7. **Geometric Calculations**: Circle, sphere, and other shape calculations
//! 8. **Physics Simulations**: Velocity, acceleration, and energy calculations
//!
//! ## Basic Examples
//!
//! ```vb
//! ' Example 1: Calculate square root of a number
//! Dim result As Double
//! result = Sqr(25)
//! ' Returns 5
//! ```
//!
//! ```vb
//! ' Example 2: Distance between two points (Pythagorean theorem)
//! Dim x1 As Double, y1 As Double
//! Dim x2 As Double, y2 As Double
//! Dim distance As Double
//!
//! x1 = 0: y1 = 0
//! x2 = 3: y2 = 4
//! distance = Sqr((x2 - x1) ^ 2 + (y2 - y1) ^ 2)
//! ' Returns 5
//! ```
//!
//! ```vb
//! ' Example 3: Calculate hypotenuse of right triangle
//! Dim sideA As Double
//! Dim sideB As Double
//! Dim hypotenuse As Double
//!
//! sideA = 3
//! sideB = 4
//! hypotenuse = Sqr(sideA ^ 2 + sideB ^ 2)
//! ' Returns 5
//! ```
//!
//! ```vb
//! ' Example 4: Quadratic formula
//! Dim a As Double, b As Double, c As Double
//! Dim discriminant As Double
//! Dim root1 As Double, root2 As Double
//!
//! a = 1: b = -5: c = 6
//! discriminant = b ^ 2 - 4 * a * c
//!
//! If discriminant >= 0 Then
//!     root1 = (-b + Sqr(discriminant)) / (2 * a)
//!     root2 = (-b - Sqr(discriminant)) / (2 * a)
//! End If
//! ```
//!
//! ## Common Patterns
//!
//! ### Pattern 1: `CalculateDistance2D`
//! Calculate distance between two 2D points
//! ```vb
//! Function CalculateDistance2D(x1 As Double, y1 As Double, _
//!                              x2 As Double, y2 As Double) As Double
//!     Dim dx As Double
//!     Dim dy As Double
//!     
//!     dx = x2 - x1
//!     dy = y2 - y1
//!     
//!     CalculateDistance2D = Sqr(dx * dx + dy * dy)
//! End Function
//! ```
//!
//! ### Pattern 2: `CalculateDistance3D`
//! Calculate distance between two 3D points
//! ```vb
//! Function CalculateDistance3D(x1 As Double, y1 As Double, z1 As Double, _
//!                              x2 As Double, y2 As Double, z2 As Double) As Double
//!     Dim dx As Double, dy As Double, dz As Double
//!     
//!     dx = x2 - x1
//!     dy = y2 - y1
//!     dz = z2 - z1
//!     
//!     CalculateDistance3D = Sqr(dx * dx + dy * dy + dz * dz)
//! End Function
//! ```
//!
//! ### Pattern 3: `CalculateHypotenuse`
//! Calculate hypotenuse of right triangle
//! ```vb
//! Function CalculateHypotenuse(sideA As Double, sideB As Double) As Double
//!     CalculateHypotenuse = Sqr(sideA ^ 2 + sideB ^ 2)
//! End Function
//! ```
//!
//! ### Pattern 4: `CalculateStandardDeviation`
//! Calculate standard deviation of values
//! ```vb
//! Function CalculateStandardDeviation(values() As Double) As Double
//!     Dim i As Integer
//!     Dim sum As Double
//!     Dim mean As Double
//!     Dim sumSquaredDiff As Double
//!     Dim count As Integer
//!     
//!     count = UBound(values) - LBound(values) + 1
//!     
//!     ' Calculate mean
//!     sum = 0
//!     For i = LBound(values) To UBound(values)
//!         sum = sum + values(i)
//!     Next i
//!     mean = sum / count
//!     
//!     ' Calculate sum of squared differences
//!     sumSquaredDiff = 0
//!     For i = LBound(values) To UBound(values)
//!         sumSquaredDiff = sumSquaredDiff + (values(i) - mean) ^ 2
//!     Next i
//!     
//!     CalculateStandardDeviation = Sqr(sumSquaredDiff / count)
//! End Function
//! ```
//!
//! ### Pattern 5: `NormalizeVector`
//! Normalize a 2D vector
//! ```vb
//! Sub NormalizeVector(x As Double, y As Double)
//!     Dim magnitude As Double
//!     
//!     magnitude = Sqr(x * x + y * y)
//!     
//!     If magnitude > 0 Then
//!         x = x / magnitude
//!         y = y / magnitude
//!     End If
//! End Sub
//! ```
//!
//! ### Pattern 6: `CalculateRMS`
//! Calculate root mean square
//! ```vb
//! Function CalculateRMS(values() As Double) As Double
//!     Dim i As Integer
//!     Dim sumSquares As Double
//!     Dim count As Integer
//!     
//!     count = UBound(values) - LBound(values) + 1
//!     sumSquares = 0
//!     
//!     For i = LBound(values) To UBound(values)
//!         sumSquares = sumSquares + values(i) ^ 2
//!     Next i
//!     
//!     CalculateRMS = Sqr(sumSquares / count)
//! End Function
//! ```
//!
//! ### Pattern 7: `SolveQuadratic`
//! Solve quadratic equation ax² + bx + c = 0
//! ```vb
//! Function SolveQuadratic(a As Double, b As Double, c As Double, _
//!                         root1 As Double, root2 As Double) As Boolean
//!     Dim discriminant As Double
//!     
//!     discriminant = b * b - 4 * a * c
//!     
//!     If discriminant < 0 Then
//!         SolveQuadratic = False
//!         Exit Function
//!     End If
//!     
//!     root1 = (-b + Sqr(discriminant)) / (2 * a)
//!     root2 = (-b - Sqr(discriminant)) / (2 * a)
//!     SolveQuadratic = True
//! End Function
//! ```
//!
//! ### Pattern 8: `CalculateCircleRadius`
//! Calculate radius from area
//! ```vb
//! Function CalculateCircleRadius(area As Double) As Double
//!     Const PI As Double = 3.14159265358979
//!     CalculateCircleRadius = Sqr(area / PI)
//! End Function
//! ```
//!
//! ### Pattern 9: `CalculateVelocity`
//! Calculate velocity from kinetic energy
//! ```vb
//! Function CalculateVelocity(kineticEnergy As Double, mass As Double) As Double
//!     ' KE = 1/2 * m * v^2
//!     ' v = Sqr(2 * KE / m)
//!     If mass > 0 Then
//!         CalculateVelocity = Sqr(2 * kineticEnergy / mass)
//!     Else
//!         CalculateVelocity = 0
//!     End If
//! End Function
//! ```
//!
//! ### Pattern 10: `IsPerfectSquare`
//! Check if number is a perfect square
//! ```vb
//! Function IsPerfectSquare(n As Long) As Boolean
//!     Dim sqrtValue As Double
//!     Dim intValue As Long
//!     
//!     If n < 0 Then
//!         IsPerfectSquare = False
//!         Exit Function
//!     End If
//!     
//!     sqrtValue = Sqr(n)
//!     intValue = CLng(sqrtValue)
//!     IsPerfectSquare = (intValue * intValue = n)
//! End Function
//! ```
//!
//! ## Advanced Usage
//!
//! ### Example 1: `GeometryHelper` Class
//! Geometric calculations using Sqr
//! ```vb
//! ' Class: GeometryHelper
//!
//! Public Function DistanceBetweenPoints(x1 As Double, y1 As Double, _
//!                                       x2 As Double, y2 As Double) As Double
//!     DistanceBetweenPoints = Sqr((x2 - x1) ^ 2 + (y2 - y1) ^ 2)
//! End Function
//!
//! Public Function PointToLineDistance(px As Double, py As Double, _
//!                                     x1 As Double, y1 As Double, _
//!                                     x2 As Double, y2 As Double) As Double
//!     ' Distance from point to line segment
//!     Dim A As Double, B As Double, C As Double
//!     
//!     A = px - x1
//!     B = py - y1
//!     C = x2 - x1
//!     Dim D As Double
//!     D = y2 - y1
//!     
//!     Dim dot As Double
//!     dot = A * C + B * D
//!     Dim lenSq As Double
//!     lenSq = C * C + D * D
//!     
//!     Dim param As Double
//!     param = -1
//!     If lenSq <> 0 Then param = dot / lenSq
//!     
//!     Dim xx As Double, yy As Double
//!     
//!     If param < 0 Then
//!         xx = x1
//!         yy = y1
//!     ElseIf param > 1 Then
//!         xx = x2
//!         yy = y2
//!     Else
//!         xx = x1 + param * C
//!         yy = y1 + param * D
//!     End If
//!     
//!     Dim dx As Double, dy As Double
//!     dx = px - xx
//!     dy = py - yy
//!     
//!     PointToLineDistance = Sqr(dx * dx + dy * dy)
//! End Function
//!
//! Public Function CircleArea(radius As Double) As Double
//!     Const PI As Double = 3.14159265358979
//!     CircleArea = PI * radius * radius
//! End Function
//!
//! Public Function CircleRadiusFromArea(area As Double) As Double
//!     Const PI As Double = 3.14159265358979
//!     CircleRadiusFromArea = Sqr(area / PI)
//! End Function
//!
//! Public Function SphereVolume(radius As Double) As Double
//!     Const PI As Double = 3.14159265358979
//!     SphereVolume = (4# / 3#) * PI * radius ^ 3
//! End Function
//!
//! Public Function SphereRadiusFromVolume(volume As Double) As Double
//!     Const PI As Double = 3.14159265358979
//!     SphereRadiusFromVolume = ((3 * volume) / (4 * PI)) ^ (1# / 3#)
//! End Function
//! ```
//!
//! ### Example 2: `StatisticsCalculator` Class
//! Statistical calculations with Sqr
//! ```vb
//! ' Class: StatisticsCalculator
//! Private m_values() As Double
//! Private m_count As Integer
//!
//! Public Sub AddValue(value As Double)
//!     If m_count > UBound(m_values) Then
//!         ReDim Preserve m_values(0 To m_count * 2)
//!     End If
//!     m_values(m_count) = value
//!     m_count = m_count + 1
//! End Sub
//!
//! Public Sub Clear()
//!     m_count = 0
//!     ReDim m_values(0 To 9)
//! End Sub
//!
//! Private Sub Class_Initialize()
//!     Clear
//! End Sub
//!
//! Public Function GetMean() As Double
//!     Dim sum As Double
//!     Dim i As Integer
//!     
//!     If m_count = 0 Then
//!         GetMean = 0
//!         Exit Function
//!     End If
//!     
//!     sum = 0
//!     For i = 0 To m_count - 1
//!         sum = sum + m_values(i)
//!     Next i
//!     
//!     GetMean = sum / m_count
//! End Function
//!
//! Public Function GetStandardDeviation() As Double
//!     Dim mean As Double
//!     Dim sumSquaredDiff As Double
//!     Dim i As Integer
//!     
//!     If m_count = 0 Then
//!         GetStandardDeviation = 0
//!         Exit Function
//!     End If
//!     
//!     mean = GetMean()
//!     sumSquaredDiff = 0
//!     
//!     For i = 0 To m_count - 1
//!         sumSquaredDiff = sumSquaredDiff + (m_values(i) - mean) ^ 2
//!     Next i
//!     
//!     GetStandardDeviation = Sqr(sumSquaredDiff / m_count)
//! End Function
//!
//! Public Function GetVariance() As Double
//!     Dim sd As Double
//!     sd = GetStandardDeviation()
//!     GetVariance = sd * sd
//! End Function
//!
//! Public Function GetRMS() As Double
//!     Dim sumSquares As Double
//!     Dim i As Integer
//!     
//!     If m_count = 0 Then
//!         GetRMS = 0
//!         Exit Function
//!     End If
//!     
//!     sumSquares = 0
//!     For i = 0 To m_count - 1
//!         sumSquares = sumSquares + m_values(i) ^ 2
//!     Next i
//!     
//!     GetRMS = Sqr(sumSquares / m_count)
//! End Function
//!
//! Public Property Get Count() As Integer
//!     Count = m_count
//! End Property
//! ```
//!
//! ### Example 3: `PhysicsEngine` Module
//! Physics calculations using Sqr
//! ```vb
//! ' Module: PhysicsEngine
//!
//! Public Function CalculateVelocityFromEnergy(kineticEnergy As Double, _
//!                                             mass As Double) As Double
//!     ' v = Sqr(2 * KE / m)
//!     If mass > 0 Then
//!         CalculateVelocityFromEnergy = Sqr(2 * kineticEnergy / mass)
//!     Else
//!         CalculateVelocityFromEnergy = 0
//!     End If
//! End Function
//!
//! Public Function CalculateEscapeVelocity(mass As Double, radius As Double) As Double
//!     ' v_escape = Sqr(2 * G * M / R)
//!     Const G As Double = 6.674E-11  ' Gravitational constant
//!     CalculateEscapeVelocity = Sqr(2 * G * mass / radius)
//! End Function
//!
//! Public Function CalculatePeriod(length As Double) As Double
//!     ' Period of simple pendulum: T = 2Ï€ * Sqr(L/g)
//!     Const PI As Double = 3.14159265358979
//!     Const g As Double = 9.81  ' Gravity
//!     CalculatePeriod = 2 * PI * Sqr(length / g)
//! End Function
//!
//! Public Function CalculateFallTime(height As Double) As Double
//!     ' Time to fall from height: t = Sqr(2h/g)
//!     Const g As Double = 9.81  ' Gravity
//!     CalculateFallTime = Sqr(2 * height / g)
//! End Function
//!
//! Public Function CalculateImpactVelocity(height As Double) As Double
//!     ' v = Sqr(2gh)
//!     Const g As Double = 9.81  ' Gravity
//!     CalculateImpactVelocity = Sqr(2 * g * height)
//! End Function
//!
//! Public Function CalculateOrbitalVelocity(mass As Double, radius As Double) As Double
//!     ' v = Sqr(G * M / R)
//!     Const G As Double = 6.674E-11  ' Gravitational constant
//!     CalculateOrbitalVelocity = Sqr(G * mass / radius)
//! End Function
//! ```
//!
//! ### Example 4: `VectorMath` Module
//! Vector operations using Sqr
//! ```vb
//! ' Module: VectorMath
//!
//! Public Function VectorMagnitude2D(x As Double, y As Double) As Double
//!     VectorMagnitude2D = Sqr(x * x + y * y)
//! End Function
//!
//! Public Function VectorMagnitude3D(x As Double, y As Double, z As Double) As Double
//!     VectorMagnitude3D = Sqr(x * x + y * y + z * z)
//! End Function
//!
//! Public Sub NormalizeVector2D(x As Double, y As Double)
//!     Dim magnitude As Double
//!     magnitude = VectorMagnitude2D(x, y)
//!     
//!     If magnitude > 0 Then
//!         x = x / magnitude
//!         y = y / magnitude
//!     End If
//! End Sub
//!
//! Public Sub NormalizeVector3D(x As Double, y As Double, z As Double)
//!     Dim magnitude As Double
//!     magnitude = VectorMagnitude3D(x, y, z)
//!     
//!     If magnitude > 0 Then
//!         x = x / magnitude
//!         y = y / magnitude
//!         z = z / magnitude
//!     End If
//! End Sub
//!
//! Public Function DotProduct2D(x1 As Double, y1 As Double, _
//!                              x2 As Double, y2 As Double) As Double
//!     DotProduct2D = x1 * x2 + y1 * y2
//! End Function
//!
//! Public Function VectorDistance2D(x1 As Double, y1 As Double, _
//!                                  x2 As Double, y2 As Double) As Double
//!     VectorDistance2D = Sqr((x2 - x1) ^ 2 + (y2 - y1) ^ 2)
//! End Function
//!
//! Public Function VectorAngleBetween(x1 As Double, y1 As Double, _
//!                                    x2 As Double, y2 As Double) As Double
//!     ' Returns angle in radians
//!     Dim dot As Double
//!     Dim mag1 As Double, mag2 As Double
//!     
//!     dot = DotProduct2D(x1, y1, x2, y2)
//!     mag1 = VectorMagnitude2D(x1, y1)
//!     mag2 = VectorMagnitude2D(x2, y2)
//!     
//!     If mag1 > 0 And mag2 > 0 Then
//!         VectorAngleBetween = Atn(Sqr(1 - (dot / (mag1 * mag2)) ^ 2) / (dot / (mag1 * mag2)))
//!     Else
//!         VectorAngleBetween = 0
//!     End If
//! End Function
//! ```
//!
//! ## Error Handling
//!
//! The Sqr function can generate the following errors:
//!
//! - **Error 5** (Invalid procedure call or argument): If number is negative
//! - **Error 13** (Type mismatch): If argument is not numeric
//!
//! Always validate inputs:
//! ```vb
//! On Error Resume Next
//! If value >= 0 Then
//!     result = Sqr(value)
//!     If Err.Number <> 0 Then
//!         MsgBox "Error calculating square root: " & Err.Description
//!     End If
//! Else
//!     MsgBox "Cannot calculate square root of negative number"
//! End If
//! ```
//!
//! ## Performance Considerations
//!
//! - Sqr is a relatively fast operation
//! - Uses hardware floating-point unit when available
//! - For repeated calculations, consider caching results
//! - Sqr(x^2) is slower than Abs(x) for getting absolute value
//! - For integer square roots, consider using Int(Sqr(x))
//!
//! ## Best Practices
//!
//! 1. **Validate Input**: Always ensure argument is non-negative
//! 2. **Use for Distances**: Ideal for Euclidean distance calculations
//! 3. **Combine with ^2**: Use for Pythagorean theorem applications
//! 4. **Handle Zero**: Remember Sqr(0) = 0 is valid
//! 5. **Precision Aware**: Understand floating-point precision limits
//! 6. **Error Handling**: Trap errors for negative inputs
//! 7. **Performance**: Cache results when used repeatedly
//! 8. **Consider Abs**: For Sqr(x^2), use Abs(x) instead
//! 9. **Document Units**: Comment on units in physics calculations
//! 10. **Test Edge Cases**: Test with 0, very small, and very large values
//!
//! ## Comparison with Related Functions
//!
//! | Operation | VB6 Function | Example | Result |
//! |-----------|--------------|---------|--------|
//! | Square root | Sqr(x) | Sqr(25) | 5 |
//! | Cube root | x^(1/3) | 27^(1/3) | 3 |
//! | Nth root | x^(1/n) | 16^(1/4) | 2 |
//! | Power | x^y | 2^3 | 8 |
//! | Absolute value | Abs(x) | Abs(-5) | 5 |
//!
//! ## Platform Considerations
//!
//! - Available in VB6, VBA (all versions)
//! - Part of core mathematical functions
//! - Uses IEEE 754 floating-point arithmetic
//! - Consistent behavior across platforms
//! - Hardware-accelerated on modern processors
//!
//! ## Limitations
//!
//! - Cannot calculate square root of negative numbers (use complex number libraries)
//! - Subject to floating-point precision limits (~15-17 significant digits)
//! - Sqr(x)^2 may not exactly equal x due to rounding
//! - Very large numbers may overflow Double range
//! - Very small numbers may underflow to zero
//!
//! ## Related Functions
//!
//! - `Abs`: Returns absolute value of a number
//! - `Exp`: Returns e raised to a power
//! - `Log`: Returns natural logarithm
//! - `^` operator: Raises number to a power (x^0.5 = Sqr(x))
//!
#[cfg(test)]
mod tests {
    use crate::*;

    #[test]
    fn sqr_basic() {
        let source = r"
Sub Test()
    Dim result As Double
    result = Sqr(25)
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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_with_variable() {
        let source = r"
Sub Test()
    Dim value As Double
    Dim sqrtValue As Double
    value = 16
    sqrtValue = Sqr(value)
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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_if_statement() {
        let source = r#"
Sub Test()
    If Sqr(value) > 10 Then
        MsgBox "Large"
    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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_function_return() {
        let source = r"
Function CalculateDistance(dx As Double, dy As Double) As Double
    CalculateDistance = Sqr(dx * dx + dy * dy)
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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_variable_assignment() {
        let source = r"
Sub Test()
    Dim hypotenuse As Double
    hypotenuse = Sqr(3 ^ 2 + 4 ^ 2)
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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_msgbox() {
        let source = r#"
Sub Test()
    MsgBox "Square root: " & Sqr(100)
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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_debug_print() {
        let source = r"
Sub Test()
    Debug.Print Sqr(144)
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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_select_case() {
        let source = r#"
Sub Test()
    Select Case Sqr(value)
        Case Is > 10
            MsgBox "Large"
        Case Is > 5
            MsgBox "Medium"
        Case Else
            MsgBox "Small"
    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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_class_usage() {
        let source = r"
Class MathHelper
    Public Function GetSquareRoot(n As Double) As Double
        GetSquareRoot = Sqr(n)
    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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_with_statement() {
        let source = r"
Sub Test()
    With calculator
        Dim root As Double
        root = Sqr(.Value)
    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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_elseif() {
        let source = r"
Sub Test()
    Dim s As Double
    If value < 0 Then
        s = 0
    ElseIf value = 0 Then
        s = 0
    Else
        s = Sqr(value)
    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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_for_loop() {
        let source = r"
Sub Test()
    Dim i As Integer
    For i = 1 To 10
        Debug.Print Sqr(i)
    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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_do_while() {
        let source = r"
Sub Test()
    Do While value > 1
        value = Sqr(value)
    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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_do_until() {
        let source = r"
Sub Test()
    Do Until Sqr(total) < threshold
        total = total - 1
    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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_while_wend() {
        let source = r"
Sub Test()
    While x >= 0
        result = Sqr(x)
        x = x - 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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_parentheses() {
        let source = r"
Sub Test()
    Dim distance As Double
    distance = (Sqr(dx * dx + dy * dy))
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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_iif() {
        let source = r"
Sub Test()
    Dim safe As Double
    safe = IIf(value >= 0, Sqr(value), 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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_array_assignment() {
        let source = r"
Sub Test()
    Dim roots(10) As Double
    roots(0) = Sqr(25)
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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_property_assignment() {
        let source = r"
Class Calculator
    Public SquareRoot As Double
End Class

Sub Test()
    Dim calc As New Calculator
    calc.SquareRoot = Sqr(value)
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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_function_argument() {
        let source = r"
Sub ProcessValue(v As Double)
End Sub

Sub Test()
    ProcessValue Sqr(100)
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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_concatenation() {
        let source = r#"
Sub Test()
    Dim msg As String
    msg = "The square root is: " & Sqr(value)
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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_comparison() {
        let source = r"
Sub Test()
    Dim isLarge As Boolean
    isLarge = (Sqr(area) > 100)
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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_arithmetic() {
        let source = r"
Sub Test()
    Dim magnitude As Double
    magnitude = Sqr(x * x + y * y + z * z)
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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_quadratic_formula() {
        let source = r"
Sub Test()
    Dim discriminant As Double
    Dim root1 As Double
    discriminant = b * b - 4 * a * c
    root1 = (-b + Sqr(discriminant)) / (2 * a)
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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_error_handling() {
        let source = r#"
Sub Test()
    On Error Resume Next
    Dim s As Double
    s = Sqr(value)
    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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_on_error_goto() {
        let source = r#"
Sub Test()
    On Error GoTo ErrorHandler
    Dim sqrtVal As Double
    sqrtVal = Sqr(number)
    Exit Sub
ErrorHandler:
    MsgBox "Error calculating square root"
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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn sqr_standard_deviation() {
        let source = r"
Sub Test()
    Dim variance As Double
    Dim stdDev As Double
    variance = 25
    stdDev = Sqr(variance)
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/math/sqr");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}