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
//! # Minute Function
//!
//! Returns a Variant (Integer) specifying a whole number between 0 and 59, inclusive, representing the minute of the hour.
//!
//! ## Syntax
//!
//! ```vb
//! Minute(time)
//! ```
//!
//! ## Parameters
//!
//! - `time` (Required): Any Variant, numeric expression, string expression, or combination that can represent a time
//!   - Can be a Date literal, Date variable, or numeric expression
//!   - String must be recognizable as a date/time
//!   - If Null, returns Null
//!   - If invalid date/time, error 13 (Type mismatch)
//!
//! ## Return Value
//!
//! Returns a Variant (Integer):
//! - Whole number from 0 to 59
//! - Represents the minute component of the time
//! - 0 = first minute of the hour (00:00-00:00:59)
//! - 59 = last minute of the hour (XX:59:00-XX:59:59)
//! - Returns Null if input is Null
//! - Independent of date component (only extracts minute)
//!
//! ## Remarks
//!
//! The Minute function extracts the minute from a time value:
//!
//! - **Returns Integer**: Value is always between 0 and 59
//! - **Time component only**: Ignores date portion of Date values
//! - **Null propagation**: Returns Null if input is Null
//! - **Type mismatch**: Error 13 if input cannot be converted to date/time
//! - **Various formats**: Accepts Date, String, or numeric time values
//! - **24-hour time**: Works with both 12-hour and 24-hour formats
//! - **Common use**: Extract minute for time calculations, formatting, validation
//! - **Related functions**: Hour (hour component), Second (second component), `TimeSerial` (create time)
//! - **Part of suite**: Day, Month, Year for dates; Hour, Minute, Second for times
//! - **Performance**: Fast operation, optimized in VB6
//! - **Available in**: All VB versions, VBA, `VBScript`
//!
//! ## Typical Uses
//!
//! 1. **Extract Minute from Time**
//!    ```vb
//!    currentMinute = Minute(Now)
//!    ```
//!
//! 2. **Format Time Display**
//!    ```vb
//!    timeText = Hour(Now) & ":" & Format(Minute(Now), "00")
//!    ```
//!
//! 3. **Validate Time Range**
//!    ```vb
//!    If Minute(appointmentTime) < 30 Then
//!        ' First half of the hour
//!    End If
//!    ```
//!
//! 4. **Round to Nearest Hour**
//!    ```vb
//!    If Minute(timeValue) >= 30 Then
//!        roundedHour = Hour(timeValue) + 1
//!    Else
//!        roundedHour = Hour(timeValue)
//!    End If
//!    ```
//!
//! 5. **Time Calculations**
//!    ```vb
//!    minutesPastHour = Minute(Time)
//!    minutesUntilHour = 60 - Minute(Time)
//!    ```
//!
//! 6. **Validate Appointment Times**
//!    ```vb
//!    If Minute(startTime) Mod 15 <> 0 Then
//!        MsgBox "Appointments must start on 15-minute intervals"
//!    End If
//!    ```
//!
//! 7. **Build Time String**
//!    ```vb
//!    timeStr = Format(Hour(t), "00") & ":" & Format(Minute(t), "00")
//!    ```
//!
//! 8. **Calculate Duration**
//!    ```vb
//!    durationMinutes = (Hour(endTime) - Hour(startTime)) * 60 + _
//!                      (Minute(endTime) - Minute(startTime))
//!    ```
//!
//! ## Basic Examples
//!
//! ### Example 1: Basic Usage
//! ```vb
//! Dim currentMinute As Integer
//! Dim timeValue As Date
//!
//! ' Get current minute
//! currentMinute = Minute(Now)        ' Returns 0-59
//!
//! ' Extract minute from specific time
//! timeValue = #2:45:30 PM#
//! currentMinute = Minute(timeValue)  ' Returns 45
//!
//! ' Extract minute from time string
//! currentMinute = Minute("3:27 PM")  ' Returns 27
//!
//! ' Extract minute from numeric value
//! currentMinute = Minute(0.5)        ' Returns 0 (noon = 12:00)
//! currentMinute = Minute(0.75)       ' Returns 0 (6 PM = 18:00)
//! ```
//!
//! ### Example 2: Digital Clock Display
//! ```vb
//! Sub UpdateClock()
//!     Dim h As Integer
//!     Dim m As Integer
//!     Dim s As Integer
//!     Dim currentTime As Date
//!     
//!     currentTime = Now
//!     
//!     h = Hour(currentTime)
//!     m = Minute(currentTime)
//!     s = Second(currentTime)
//!     
//!     ' Display in 24-hour format
//!     lblClock.Caption = Format(h, "00") & ":" & _
//!                       Format(m, "00") & ":" & _
//!                       Format(s, "00")
//!     
//!     ' Display in 12-hour format
//!     Dim ampm As String
//!     Dim h12 As Integer
//!     
//!     If h >= 12 Then
//!         ampm = "PM"
//!         h12 = IIf(h = 12, 12, h - 12)
//!     Else
//!         ampm = "AM"
//!         h12 = IIf(h = 0, 12, h)
//!     End If
//!     
//!     lblClock12.Caption = h12 & ":" & Format(m, "00") & " " & ampm
//! End Sub
//! ```
//!
//! ### Example 3: Appointment Scheduler Validation
//! ```vb
//! Function ValidateAppointmentTime(ByVal appointmentTime As Date) As Boolean
//!     Dim m As Integer
//!     
//!     m = Minute(appointmentTime)
//!     
//!     ' Check if time is on a 15-minute interval
//!     If m Mod 15 = 0 Then
//!         ValidateAppointmentTime = True
//!     Else
//!         MsgBox "Appointments must start on 15-minute intervals" & vbCrLf & _
//!                "Valid minutes: 00, 15, 30, 45", _
//!                vbExclamation, "Invalid Time"
//!         ValidateAppointmentTime = False
//!     End If
//! End Function
//!
//! ' Usage:
//! ' If ValidateAppointmentTime(#2:15 PM#) Then  ' Valid
//! ' If ValidateAppointmentTime(#2:23 PM#) Then  ' Invalid
//! ```
//!
//! ### Example 4: Time Rounding
//! ```vb
//! Function RoundToNearestQuarterHour(ByVal timeValue As Date) As Date
//!     Dim h As Integer
//!     Dim m As Integer
//!     Dim roundedMinute As Integer
//!     
//!     h = Hour(timeValue)
//!     m = Minute(timeValue)
//!     
//!     ' Round to nearest 15 minutes
//!     Select Case m
//!         Case 0 To 7
//!             roundedMinute = 0
//!         Case 8 To 22
//!             roundedMinute = 15
//!         Case 23 To 37
//!             roundedMinute = 30
//!         Case 38 To 52
//!             roundedMinute = 45
//!         Case 53 To 59
//!             roundedMinute = 0
//!             h = h + 1
//!             If h = 24 Then h = 0
//!     End Select
//!     
//!     RoundToNearestQuarterHour = TimeSerial(h, roundedMinute, 0)
//! End Function
//!
//! ' Usage:
//! ' rounded = RoundToNearestQuarterHour(#2:23 PM#)  ' Returns #2:30 PM#
//! ' rounded = RoundToNearestQuarterHour(#2:57 PM#)  ' Returns #3:00 PM#
//! ```
//!
//! ## Common Patterns
//!
//! ### Pattern 1: `SafeMinute` (handle Null)
//! ```vb
//! Function SafeMinute(ByVal timeValue As Variant) As Integer
//!     If IsNull(timeValue) Then
//!         SafeMinute = 0
//!     ElseIf Not IsDate(timeValue) Then
//!         SafeMinute = 0
//!     Else
//!         SafeMinute = Minute(timeValue)
//!     End If
//! End Function
//! ```
//!
//! ### Pattern 2: `IsTopOfHour`
//! ```vb
//! Function IsTopOfHour(ByVal timeValue As Date) As Boolean
//!     IsTopOfHour = (Minute(timeValue) = 0 And Second(timeValue) = 0)
//! End Function
//! ```
//!
//! ### Pattern 3: `GetMinutesPastHour`
//! ```vb
//! Function GetMinutesPastHour(ByVal timeValue As Date) As Integer
//!     GetMinutesPastHour = Minute(timeValue)
//! End Function
//! ```
//!
//! ### Pattern 4: `GetMinutesUntilNextHour`
//! ```vb
//! Function GetMinutesUntilNextHour(ByVal timeValue As Date) As Integer
//!     Dim m As Integer
//!     m = Minute(timeValue)
//!     
//!     If m = 0 And Second(timeValue) = 0 Then
//!         GetMinutesUntilNextHour = 60
//!     Else
//!         GetMinutesUntilNextHour = 60 - m
//!         If Second(timeValue) > 0 Then
//!             GetMinutesUntilNextHour = GetMinutesUntilNextHour - 1
//!         End If
//!     End If
//! End Function
//! ```
//!
//! ### Pattern 5: `FormatMinute`
//! ```vb
//! Function FormatMinute(ByVal timeValue As Date) As String
//!     FormatMinute = Format(Minute(timeValue), "00")
//! End Function
//! ```
//!
//! ### Pattern 6: `IsQuarterHour`
//! ```vb
//! Function IsQuarterHour(ByVal timeValue As Date) As Boolean
//!     IsQuarterHour = (Minute(timeValue) Mod 15 = 0)
//! End Function
//! ```
//!
//! ### Pattern 7: `GetQuarterHourIndex`
//! ```vb
//! Function GetQuarterHourIndex(ByVal timeValue As Date) As Integer
//!     ' Returns 0-3 for which quarter hour (0=:00, 1=:15, 2=:30, 3=:45)
//!     GetQuarterHourIndex = Minute(timeValue) \ 15
//! End Function
//! ```
//!
//! ### Pattern 8: `IsHalfHour`
//! ```vb
//! Function IsHalfHour(ByVal timeValue As Date) As Boolean
//!     IsHalfHour = (Minute(timeValue) = 0 Or Minute(timeValue) = 30)
//! End Function
//! ```
//!
//! ### Pattern 9: `CompareMinutes`
//! ```vb
//! Function CompareMinutes(ByVal time1 As Date, ByVal time2 As Date) As Integer
//!     CompareMinutes = Minute(time1) - Minute(time2)
//! End Function
//! ```
//!
//! ### Pattern 10: `MinutesSinceMidnight`
//! ```vb
//! Function MinutesSinceMidnight(ByVal timeValue As Date) As Long
//!     MinutesSinceMidnight = Hour(timeValue) * 60 + Minute(timeValue)
//! End Function
//! ```
//!
//! ## Advanced Examples
//!
//! ### Example 1: Time Slot Scheduler
//! ```vb
//! ' Class: TimeSlotScheduler
//! Private m_slotDuration As Integer  ' Minutes per slot
//! Private m_slots As Collection
//!
//! Private Sub Class_Initialize()
//!     m_slotDuration = 30  ' Default 30-minute slots
//!     Set m_slots = New Collection
//! End Sub
//!
//! Public Property Let SlotDuration(ByVal minutes As Integer)
//!     If minutes > 0 And minutes <= 60 And (60 Mod minutes = 0) Then
//!         m_slotDuration = minutes
//!     Else
//!         Err.Raise 5, , "Slot duration must evenly divide 60 (5, 10, 15, 20, 30, or 60)"
//!     End If
//! End Property
//!
//! Public Function GetSlotIndex(ByVal timeValue As Date) As Integer
//!     Dim totalMinutes As Long
//!     totalMinutes = Hour(timeValue) * 60 + Minute(timeValue)
//!     GetSlotIndex = totalMinutes \ m_slotDuration
//! End Function
//!
//! Public Function GetSlotStartTime(ByVal slotIndex As Integer) As Date
//!     Dim totalMinutes As Long
//!     Dim h As Integer
//!     Dim m As Integer
//!     
//!     totalMinutes = slotIndex * m_slotDuration
//!     h = totalMinutes \ 60
//!     m = totalMinutes Mod 60
//!     
//!     GetSlotStartTime = TimeSerial(h, m, 0)
//! End Function
//!
//! Public Function IsSlotAvailable(ByVal slotIndex As Integer) As Boolean
//!     On Error Resume Next
//!     Dim temp As Variant
//!     temp = m_slots(CStr(slotIndex))
//!     IsSlotAvailable = (Err.Number <> 0)
//!     On Error GoTo 0
//! End Function
//!
//! Public Sub BookSlot(ByVal slotIndex As Integer, ByVal description As String)
//!     If IsSlotAvailable(slotIndex) Then
//!         m_slots.Add description, CStr(slotIndex)
//!     Else
//!         Err.Raise 5, , "Slot already booked"
//!     End If
//! End Sub
//!
//! Public Function GetSlotsInHour(ByVal hour As Integer) As Integer
//!     GetSlotsInHour = 60 \ m_slotDuration
//! End Function
//! ```
//!
//! ### Example 2: Timesheet Entry Validator
//! ```vb
//! ' Class: TimesheetValidator
//! Private m_roundingInterval As Integer
//!
//! Private Sub Class_Initialize()
//!     m_roundingInterval = 15  ' Default to 15-minute intervals
//! End Sub
//!
//! Public Property Let RoundingInterval(ByVal minutes As Integer)
//!     Select Case minutes
//!         Case 1, 5, 10, 15, 30
//!             m_roundingInterval = minutes
//!         Case Else
//!             Err.Raise 5, , "Invalid rounding interval"
//!     End Select
//! End Property
//!
//! Public Function ValidateTime(ByVal timeValue As Date) As Boolean
//!     Dim m As Integer
//!     m = Minute(timeValue)
//!     ValidateTime = (m Mod m_roundingInterval = 0)
//! End Function
//!
//! Public Function RoundTime(ByVal timeValue As Date, _
//!                          Optional ByVal roundUp As Boolean = False) As Date
//!     Dim h As Integer
//!     Dim m As Integer
//!     Dim s As Integer
//!     Dim roundedMinute As Integer
//!     
//!     h = Hour(timeValue)
//!     m = Minute(timeValue)
//!     s = Second(timeValue)
//!     
//!     If roundUp Then
//!         ' Round up to next interval
//!         roundedMinute = ((m \ m_roundingInterval) + 1) * m_roundingInterval
//!         If roundedMinute >= 60 Then
//!             roundedMinute = 0
//!             h = h + 1
//!             If h = 24 Then h = 0
//!         End If
//!     Else
//!         ' Round to nearest interval
//!         Dim remainder As Integer
//!         remainder = m Mod m_roundingInterval
//!         
//!         If remainder >= (m_roundingInterval \ 2) Or s > 0 Then
//!             roundedMinute = m - remainder + m_roundingInterval
//!             If roundedMinute >= 60 Then
//!                 roundedMinute = 0
//!                 h = h + 1
//!                 If h = 24 Then h = 0
//!             End If
//!         Else
//!             roundedMinute = m - remainder
//!         End If
//!     End If
//!     
//!     RoundTime = TimeSerial(h, roundedMinute, 0)
//! End Function
//!
//! Public Function GetTimesheetString(ByVal timeValue As Date) As String
//!     GetTimesheetString = Format(Hour(timeValue), "00") & ":" & _
//!                         Format(Minute(timeValue), "00")
//! End Function
//! ```
//!
//! ### Example 3: Meeting Reminder System
//! ```vb
//! ' Module: MeetingReminders
//!
//! Public Function CheckReminders() As Collection
//!     Dim reminders As New Collection
//!     Dim currentTime As Date
//!     Dim currentMinute As Integer
//!     
//!     currentTime = Now
//!     currentMinute = Minute(currentTime)
//!     
//!     ' Check for hourly reminder (at :00)
//!     If currentMinute = 0 Then
//!         reminders.Add "Top of the hour reminder"
//!     End If
//!     
//!     ' Check for quarter-hour reminders
//!     If currentMinute Mod 15 = 0 Then
//!         reminders.Add "Quarter hour: " & Format(currentTime, "h:mm AM/PM")
//!     End If
//!     
//!     ' Check for upcoming meeting (5 minutes before)
//!     If currentMinute Mod 60 = 25 Or currentMinute Mod 60 = 55 Then
//!         reminders.Add "Meeting in 5 minutes"
//!     End If
//!     
//!     Set CheckReminders = reminders
//! End Function
//!
//! Public Function GetNextQuarterHour(ByVal fromTime As Date) As Date
//!     Dim h As Integer
//!     Dim m As Integer
//!     Dim nextMinute As Integer
//!     
//!     h = Hour(fromTime)
//!     m = Minute(fromTime)
//!     
//!     ' Calculate next quarter hour
//!     nextMinute = ((m \ 15) + 1) * 15
//!     
//!     If nextMinute >= 60 Then
//!         nextMinute = 0
//!         h = h + 1
//!         If h = 24 Then h = 0
//!     End If
//!     
//!     GetNextQuarterHour = TimeSerial(h, nextMinute, 0)
//! End Function
//!
//! Public Function MinutesUntilQuarterHour(ByVal fromTime As Date) As Integer
//!     Dim m As Integer
//!     Dim remainder As Integer
//!     
//!     m = Minute(fromTime)
//!     remainder = m Mod 15
//!     
//!     If remainder = 0 Then
//!         MinutesUntilQuarterHour = 15
//!     Else
//!         MinutesUntilQuarterHour = 15 - remainder
//!     End If
//! End Function
//! ```
//!
//! ### Example 4: Bus Schedule Matcher
//! ```vb
//! ' Class: BusSchedule
//! Private m_departureMinutes() As Integer
//! Private m_routeName As String
//!
//! Public Sub Initialize(ByVal routeName As String, departureMinutes As Variant)
//!     Dim i As Long
//!     m_routeName = routeName
//!     
//!     ReDim m_departureMinutes(LBound(departureMinutes) To UBound(departureMinutes))
//!     For i = LBound(departureMinutes) To UBound(departureMinutes)
//!         m_departureMinutes(i) = departureMinutes(i)
//!     Next i
//! End Sub
//!
//! Public Function GetNextDeparture(ByVal currentTime As Date) As Date
//!     Dim currentMinuteOfDay As Long
//!     Dim i As Long
//!     Dim h As Integer
//!     Dim m As Integer
//!     
//!     currentMinuteOfDay = Hour(currentTime) * 60 + Minute(currentTime)
//!     
//!     ' Find next departure
//!     For i = LBound(m_departureMinutes) To UBound(m_departureMinutes)
//!         If m_departureMinutes(i) > currentMinuteOfDay Then
//!             h = m_departureMinutes(i) \ 60
//!             m = m_departureMinutes(i) Mod 60
//!             GetNextDeparture = TimeSerial(h, m, 0)
//!             Exit Function
//!         End If
//!     Next i
//!     
//!     ' No more departures today, return first tomorrow
//!     h = m_departureMinutes(LBound(m_departureMinutes)) \ 60
//!     m = m_departureMinutes(LBound(m_departureMinutes)) Mod 60
//!     GetNextDeparture = DateSerial(Year(currentTime), Month(currentTime), Day(currentTime) + 1) + _
//!                        TimeSerial(h, m, 0)
//! End Function
//!
//! Public Function GetMinutesUntilNext(ByVal currentTime As Date) As Long
//!     Dim nextDeparture As Date
//!     nextDeparture = GetNextDeparture(currentTime)
//!     
//!     GetMinutesUntilNext = DateDiff("n", currentTime, nextDeparture)
//! End Function
//!
//! Public Function IsAtDeparture(ByVal currentTime As Date, _
//!                              Optional ByVal toleranceMinutes As Integer = 0) As Boolean
//!     Dim currentMinuteOfDay As Long
//!     Dim i As Long
//!     
//!     currentMinuteOfDay = Hour(currentTime) * 60 + Minute(currentTime)
//!     
//!     For i = LBound(m_departureMinutes) To UBound(m_departureMinutes)
//!         If Abs(m_departureMinutes(i) - currentMinuteOfDay) <= toleranceMinutes Then
//!             IsAtDeparture = True
//!             Exit Function
//!         End If
//!     Next i
//!     
//!     IsAtDeparture = False
//! End Function
//! ```
//!
//! ## Error Handling
//!
//! ```vb
//! ' Error 13: Type mismatch
//! ' - Input cannot be converted to date/time
//!
//! ' Safe minute extraction with error handling
//! Function SafeGetMinute(ByVal timeValue As Variant) As Integer
//!     On Error GoTo ErrorHandler
//!     
//!     If IsNull(timeValue) Then
//!         SafeGetMinute = 0
//!     ElseIf Not IsDate(timeValue) Then
//!         SafeGetMinute = 0
//!     Else
//!         SafeGetMinute = Minute(timeValue)
//!     End If
//!     
//!     Exit Function
//!     
//! ErrorHandler:
//!     SafeGetMinute = 0
//! End Function
//!
//! ' Validate before extracting
//! Function GetMinuteOrDefault(ByVal timeValue As Variant, _
//!                            Optional ByVal defaultValue As Integer = 0) As Integer
//!     If IsNull(timeValue) Then
//!         GetMinuteOrDefault = defaultValue
//!     ElseIf IsDate(timeValue) Then
//!         GetMinuteOrDefault = Minute(timeValue)
//!     Else
//!         GetMinuteOrDefault = defaultValue
//!     End If
//! End Function
//! ```
//!
//! ## Performance Considerations
//!
//! - **Fast Operation**: Extracting time components is highly optimized in VB6
//! - **No String Parsing**: Direct access to internal time representation
//! - **Cache for Repeated Use**: If calling multiple times on same value
//! - **Combine Extractions**: Use Hour, Minute, Second together efficiently
//!
//! ## Best Practices
//!
//! 1. **Use with Format** - Pad with leading zero: `Format(Minute(t), "00")`
//! 2. **Validate input** - Check `IsDate` before calling Minute
//! 3. **Handle Null gracefully** - Use `IsNull` check for Variant inputs
//! 4. **Combine with Hour/Second** - Extract all time components together
//! 5. **Use for validation** - Check minute intervals for appointments
//! 6. **Consider `TimeSerial`** - To reconstruct time from components
//! 7. **Document assumptions** - Clarify if using 0-59 or 1-60 range
//! 8. **Use constants** - Define meaningful minute values (`TOP_OF_HOUR` = 0)
//! 9. **Test edge cases** - Null values, invalid strings, midnight
//! 10. **Remember range** - Always 0-59, never 60 or negative
//!
//! ## Comparison with Related Functions
//!
//! | Function | Returns | Range | Use Case |
//! |----------|---------|-------|----------|
//! | **Minute** | Minute of hour | 0-59 | Extract minute component |
//! | **Hour** | Hour of day | 0-23 | Extract hour component |
//! | **Second** | Second of minute | 0-59 | Extract second component |
//! | **`TimeSerial`** | Date/Time | N/A | Create time from components |
//!
//! ## Minute vs Hour vs Second
//!
//! ```vb
//! Dim timeValue As Date
//! timeValue = #2:45:30 PM#
//!
//! ' Extract individual components
//! Debug.Print Hour(timeValue)    ' 14 (2 PM in 24-hour format)
//! Debug.Print Minute(timeValue)  ' 45
//! Debug.Print Second(timeValue)  ' 30
//!
//! ' Reconstruct time
//! Dim reconstructed As Date
//! reconstructed = TimeSerial(Hour(timeValue), Minute(timeValue), Second(timeValue))
//! ' reconstructed = #2:45:30 PM#
//!
//! ' Format as string
//! Debug.Print Format(Hour(timeValue), "00") & ":" & _
//!            Format(Minute(timeValue), "00") & ":" & _
//!            Format(Second(timeValue), "00")
//! ' Output: "14:45:30"
//! ```
//!
//! ## Minute Range (0-59)
//!
//! ```vb
//! ' Minute function always returns 0-59
//! Debug.Print Minute(#12:00:00 AM#)  ' 0 (midnight)
//! Debug.Print Minute(#12:15:00 AM#)  ' 15
//! Debug.Print Minute(#12:30:00 AM#)  ' 30
//! Debug.Print Minute(#12:45:00 AM#)  ' 45
//! Debug.Print Minute(#12:59:59 PM#)  ' 59 (last minute of noon hour)
//! Debug.Print Minute(#11:59:59 PM#)  ' 59 (last minute before midnight)
//!
//! ' Common minute values
//! Const TOP_OF_HOUR As Integer = 0
//! Const QUARTER_PAST As Integer = 15
//! Const HALF_PAST As Integer = 30
//! Const QUARTER_TO As Integer = 45
//! ```
//!
//! ## Platform Notes
//!
//! - Available in all VB6 versions
//! - Part of VBA core library
//! - Available in `VBScript`
//! - Returns Integer (not Long)
//! - Range is always 0-59 (inclusive)
//! - Handles Null by returning Null
//! - Type mismatch error for invalid input
//! - Same behavior across all Windows versions
//! - Works with Date variables and literals
//! - Ignores date component of Date values
//!
//! ## Limitations
//!
//! - **No milliseconds**: Does not access millisecond component
//! - **Integer only**: Returns whole minutes, not fractional
//! - **No timezone**: Does not handle timezone information
//! - **Type mismatch**: Error 13 for non-date inputs
//! - **Null propagation**: Returns Null for Null input (may need handling)
//!
//! ## Related Functions
//!
//! - `Hour`: Returns hour component (0-23)
//! - `Second`: Returns second component (0-59)
//! - `Day`: Returns day of month (1-31)
//! - `Month`: Returns month (1-12)
//! - `Year`: Returns year
//! - `Now`: Returns current date and time
//! - `Time`: Returns current time
//! - `TimeSerial`: Creates time from hour, minute, second
//! - `TimeValue`: Converts string to time
//! - `Format`: Formats date/time as string

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

    #[test]
    fn minute_basic() {
        let source = r"
            currentMinute = Minute(Now)
        ";
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_variable() {
        let source = r"
            m = Minute(timeValue)
        ";
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_time_literal() {
        let source = r"
            m = Minute(#2:45:30 PM#)
        ";
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_if_statement() {
        let source = r#"
            If Minute(appointmentTime) < 30 Then
                MsgBox "First half"
            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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_function_return() {
        let source = r"
            Function GetMinute() As Integer
                GetMinute = Minute(Time)
            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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_mod_validation() {
        let source = r#"
            If Minute(startTime) Mod 15 <> 0 Then
                MsgBox "Invalid"
            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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_debug_print() {
        let source = r"
            Debug.Print Minute(Now)
        ";
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_with_statement() {
        let source = r"
            With appointmentRecord
                .StartMinute = Minute(.StartTime)
            End With
        ";
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_select_case() {
        let source = r#"
            Select Case Minute(currentTime)
                Case 0
                    MsgBox "Top of hour"
                Case 15, 30, 45
                    MsgBox "Quarter hour"
            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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_elseif() {
        let source = r#"
            If m = 0 Then
                status = "Top"
            ElseIf Minute(t) = 30 Then
                status = "Half"
            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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_parentheses() {
        let source = r"
            result = (Minute(timeValue))
        ";
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_iif() {
        let source = r#"
            result = IIf(Minute(t) >= 30, "Late", "Early")
        "#;
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_in_class() {
        let source = r"
            Private Sub ExtractTime()
                m_minute = Minute(m_timeValue)
            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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_function_argument() {
        let source = r"
            Call ProcessMinute(Minute(Now))
        ";
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_property_assignment() {
        let source = r"
            MyObject.CurrentMinute = Minute(Time)
        ";
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_array_assignment() {
        let source = r"
            minutes(i) = Minute(times(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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_for_loop() {
        let source = r"
            For i = 1 To count
                m = Minute(appointments(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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_while_wend() {
        let source = r"
            While Minute(currentTime) < 30
                DoWork
            Wend
        ";
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_do_while() {
        let source = r"
            Do While i < recordCount
                minuteValue = Minute(records(i).Time)
                i = i + 1
            Loop
        ";
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_do_until() {
        let source = r"
            Do Until Minute(Now) = 0
                Wait 1000
            Loop
        ";
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_msgbox() {
        let source = r#"
            MsgBox "Minute: " & Minute(Now)
        "#;
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_concatenation() {
        let source = r#"
            timeStr = Hour(t) & ":" & Format(Minute(t), "00")
        "#;
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_comparison() {
        let source = r#"
            If Minute(time1) = Minute(time2) Then
                MsgBox "Same"
            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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_with_format() {
        let source = r#"
            formatted = Format(Minute(Now), "00")
        "#;
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_arithmetic() {
        let source = r"
            minutesPast = Minute(currentTime)
            minutesLeft = 60 - Minute(currentTime)
        ";
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_label_caption() {
        let source = r"
            lblMinute.Caption = CStr(Minute(Time))
        ";
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn minute_calculation() {
        let source = r"
            totalMinutes = Hour(t) * 60 + Minute(t)
        ";
        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/datetime/minute");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}