vb6parse 1.0.1

vb6parse is a library for parsing and analyzing VB6 code, from projects, to controls, to modules, and forms.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
//! # Now Function
//!
//! Returns a Variant (Date) specifying the current date and time according to the setting of the computer's system date and time.
//!
//! ## Syntax
//!
//! ```vb
//! Now
//! ```
//!
//! ## Parameters
//!
//! None. Now takes no parameters.
//!
//! ## Return Value
//!
//! Returns a **Variant (Date)** containing the current system date and time.
//!
//! The returned value includes both the date portion (number of days since December 30, 1899) and the time portion (fractional part of a 24-hour day).
//!
//! ## Remarks
//!
//! The Now function is one of the most frequently used VB6 date/time functions for getting the current moment.
//! It combines both date and time information in a single value.
//!
//! ### Key Characteristics:
//! - Returns both date and time components
//! - Based on computer's system clock
//! - No parameters required (parameterless function)
//! - Commonly used for timestamps, logging, and timing operations
//! - Can be separated into date-only or time-only using `Date()` or `Time()`
//! - Precision to the second (does not include milliseconds)
//! - Returns Variant (Date) type
//! - Subject to system time zone settings
//!
//! ### Comparison with Related Functions:
//! - **Date** - Returns only the date portion (time is midnight)
//! - **Time** - Returns only the time portion (date is December 30, 1899)
//! - **Now** - Returns both date and time components
//! - **Timer** - Returns seconds since midnight as Single (for precision timing)
//!
//! ### Common Use Cases:
//! - Create timestamps for logging
//! - Record when events occur
//! - Calculate elapsed time
//! - Display current date and time to users
//! - Set default values for date fields
//! - Generate time-based filenames
//! - Track operation start/end times
//! - Audit trail creation
//!
//! ## Typical Uses
//!
//! 1. **Timestamps** - Record when operations occur
//! 2. **Logging** - Add timestamps to log entries
//! 3. **Audit Trails** - Track when records are created/modified
//! 4. **Performance Timing** - Measure operation duration
//! 5. **Display Current Time** - Show users the current date/time
//! 6. **Default Values** - Initialize date fields with current date/time
//! 7. **File Naming** - Create time-stamped file names
//! 8. **Session Tracking** - Record login/logout times
//!
//! ## Basic Examples
//!
//! ```vb
//! ' Example 1: Get current date and time
//! Dim currentDateTime As Date
//! currentDateTime = Now
//! ```
//!
//! ```vb
//! ' Example 2: Display to user
//! MsgBox "Current time is: " & Now
//! ```
//!
//! ```vb
//! ' Example 3: Create timestamp
//! Dim timestamp As String
//! timestamp = Format(Now, "yyyy-mm-dd hh:nn:ss")
//! ```
//!
//! ```vb
//! ' Example 4: Calculate elapsed time
//! Dim startTime As Date
//! startTime = Now
//! ' ... do some work ...
//! MsgBox "Elapsed: " & DateDiff("s", startTime, Now) & " seconds"
//! ```
//!
//! ## Common Patterns
//!
//! ```vb
//! ' Pattern 1: Simple timestamp logging
//! Sub LogMessage(message As String)
//!     Debug.Print Now & " - " & message
//! End Sub
//! ```
//!
//! ```vb
//! ' Pattern 2: Formatted timestamp
//! Function GetTimestamp() As String
//!     GetTimestamp = Format(Now, "yyyy-mm-dd hh:nn:ss")
//! End Function
//! ```
//!
//! ```vb
//! ' Pattern 3: Calculate operation duration
//! Function MeasureOperation() As Double
//!     Dim startTime As Date
//!     Dim endTime As Date
//!     
//!     startTime = Now
//!     
//!     ' Perform operation
//!     DoSomething
//!     
//!     endTime = Now
//!     
//!     ' Return elapsed seconds
//!     MeasureOperation = DateDiff("s", startTime, endTime)
//! End Function
//! ```
//!
//! ```vb
//! ' Pattern 4: Audit trail update
//! Sub UpdateRecord(recordID As Long)
//!     Dim sql As String
//!     sql = "UPDATE Records SET ModifiedDate = " & _
//!           Format(Now, "\#mm\/dd\/yyyy hh:nn:ss\#") & _
//!           " WHERE ID = " & recordID
//!     ExecuteSQL sql
//! End Sub
//! ```
//!
//! ```vb
//! ' Pattern 5: Time-stamped filename
//! Function GetLogFileName() As String
//!     GetLogFileName = "log_" & Format(Now, "yyyymmdd_hhnnss") & ".txt"
//! End Function
//! ```
//!
//! ```vb
//! ' Pattern 6: Session tracking
//! Sub RecordLogin(userID As Long)
//!     Dim loginTime As Date
//!     loginTime = Now
//!     
//!     ' Store in database or session object
//!     Session("LoginTime") = loginTime
//!     Session("UserID") = userID
//! End Sub
//! ```
//!
//! ```vb
//! ' Pattern 7: Timeout checking
//! Function IsTimedOut(startTime As Date, timeoutMinutes As Long) As Boolean
//!     Dim elapsed As Long
//!     elapsed = DateDiff("n", startTime, Now)
//!     IsTimedOut = (elapsed >= timeoutMinutes)
//! End Function
//! ```
//!
//! ```vb
//! ' Pattern 8: Scheduled task checking
//! Function ShouldRunTask(lastRun As Date, intervalHours As Long) As Boolean
//!     Dim hoursSinceRun As Long
//!     
//!     If IsNull(lastRun) Then
//!         ShouldRunTask = True
//!     Else
//!         hoursSinceRun = DateDiff("h", lastRun, Now)
//!         ShouldRunTask = (hoursSinceRun >= intervalHours)
//!     End If
//! End Function
//! ```
//!
//! ```vb
//! ' Pattern 9: Display relative time
//! Function GetTimeAgo(pastTime As Date) As String
//!     Dim seconds As Long
//!     Dim minutes As Long
//!     Dim hours As Long
//!     
//!     seconds = DateDiff("s", pastTime, Now)
//!     
//!     If seconds < 60 Then
//!         GetTimeAgo = seconds & " seconds ago"
//!     ElseIf seconds < 3600 Then
//!         minutes = seconds \ 60
//!         GetTimeAgo = minutes & " minutes ago"
//!     Else
//!         hours = seconds \ 3600
//!         GetTimeAgo = hours & " hours ago"
//!     End If
//! End Function
//! ```
//!
//! ```vb
//! ' Pattern 10: Business hours check
//! Function IsDuringBusinessHours() As Boolean
//!     Dim currentHour As Integer
//!     Dim currentDay As Integer
//!     
//!     currentHour = Hour(Now)
//!     currentDay = Weekday(Now)
//!     
//!     ' Monday-Friday, 9 AM to 5 PM
//!     IsDuringBusinessHours = (currentDay >= vbMonday And currentDay <= vbFriday) And _
//!                             (currentHour >= 9 And currentHour < 17)
//! End Function
//! ```
//!
//! ## Advanced Usage
//!
//! ### Example 1: Performance Monitor Class
//!
//! ```vb
//! ' Class: PerformanceMonitor
//! ' Tracks operation performance with detailed timing
//!
//! Option Explicit
//!
//! Private m_operations As Collection
//!
//! Private Type OperationTiming
//!     operationName As String
//!     startTime As Date
//!     endTime As Date
//!     duration As Double
//! End Type
//!
//! Private Sub Class_Initialize()
//!     Set m_operations = New Collection
//! End Sub
//!
//! Public Sub StartOperation(operationName As String)
//!     Dim timing As OperationTiming
//!     
//!     timing.operationName = operationName
//!     timing.startTime = Now
//!     timing.endTime = 0
//!     timing.duration = 0
//!     
//!     m_operations.Add timing, operationName
//! End Sub
//!
//! Public Sub EndOperation(operationName As String)
//!     Dim timing As OperationTiming
//!     Dim i As Long
//!     
//!     ' Find the operation
//!     For i = 1 To m_operations.Count
//!         timing = m_operations(i)
//!         If timing.operationName = operationName Then
//!             timing.endTime = Now
//!             timing.duration = DateDiff("s", timing.startTime, timing.endTime)
//!             
//!             ' Update the collection
//!             m_operations.Remove i
//!             m_operations.Add timing, operationName
//!             Exit Sub
//!         End If
//!     Next i
//! End Sub
//!
//! Public Function GetDuration(operationName As String) As Double
//!     Dim timing As OperationTiming
//!     Dim i As Long
//!     
//!     For i = 1 To m_operations.Count
//!         timing = m_operations(i)
//!         If timing.operationName = operationName Then
//!             If timing.endTime = 0 Then
//!                 ' Still running - calculate current duration
//!                 GetDuration = DateDiff("s", timing.startTime, Now)
//!             Else
//!                 GetDuration = timing.duration
//!             End If
//!             Exit Function
//!         End If
//!     Next i
//!     
//!     GetDuration = -1 ' Not found
//! End Function
//!
//! Public Function GenerateReport() As String
//!     Dim report As String
//!     Dim timing As OperationTiming
//!     Dim i As Long
//!     
//!     report = "Performance Report - " & Format(Now, "yyyy-mm-dd hh:nn:ss") & vbCrLf
//!     report = report & String(60, "-") & vbCrLf
//!     
//!     For i = 1 To m_operations.Count
//!         timing = m_operations(i)
//!         report = report & timing.operationName & ": "
//!         
//!         If timing.endTime = 0 Then
//!             report = report & "Running (" & DateDiff("s", timing.startTime, Now) & "s)"
//!         Else
//!             report = report & timing.duration & " seconds"
//!         End If
//!         
//!         report = report & vbCrLf
//!     Next i
//!     
//!     GenerateReport = report
//! End Function
//! ```
//!
//! ### Example 2: Audit Logger Class
//!
//! ```vb
//! ' Class: AuditLogger
//! ' Logs all database operations with timestamps
//!
//! Option Explicit
//!
//! Private m_logFile As String
//! Private m_enabled As Boolean
//!
//! Public Sub Initialize(logFilePath As String)
//!     m_logFile = logFilePath
//!     m_enabled = True
//! End Sub
//!
//! Public Sub LogInsert(tableName As String, recordID As Variant, userName As String)
//!     Dim entry As String
//!     entry = FormatLogEntry("INSERT", tableName, recordID, userName, "")
//!     WriteToLog entry
//! End Sub
//!
//! Public Sub LogUpdate(tableName As String, recordID As Variant, userName As String, changes As String)
//!     Dim entry As String
//!     entry = FormatLogEntry("UPDATE", tableName, recordID, userName, changes)
//!     WriteToLog entry
//! End Sub
//!
//! Public Sub LogDelete(tableName As String, recordID As Variant, userName As String)
//!     Dim entry As String
//!     entry = FormatLogEntry("DELETE", tableName, recordID, userName, "")
//!     WriteToLog entry
//! End Sub
//!
//! Public Sub LogSelect(tableName As String, userName As String, criteria As String)
//!     Dim entry As String
//!     entry = FormatLogEntry("SELECT", tableName, "", userName, criteria)
//!     WriteToLog entry
//! End Sub
//!
//! Private Function FormatLogEntry(operation As String, _
//!                                tableName As String, _
//!                                recordID As Variant, _
//!                                userName As String, _
//!                                details As String) As String
//!     Dim entry As String
//!     
//!     entry = Format(Now, "yyyy-mm-dd hh:nn:ss") & vbTab
//!     entry = entry & operation & vbTab
//!     entry = entry & tableName & vbTab
//!     entry = entry & CStr(recordID) & vbTab
//!     entry = entry & userName & vbTab
//!     entry = entry & details
//!     
//!     FormatLogEntry = entry
//! End Function
//!
//! Private Sub WriteToLog(entry As String)
//!     Dim fileNum As Integer
//!     
//!     If Not m_enabled Then Exit Sub
//!     
//!     On Error Resume Next
//!     fileNum = FreeFile
//!     Open m_logFile For Append As #fileNum
//!     Print #fileNum, entry
//!     Close #fileNum
//!     On Error GoTo 0
//! End Sub
//!
//! Public Function GetRecentEntries(minutes As Long) As Collection
//!     Dim entries As New Collection
//!     Dim fileNum As Integer
//!     Dim line As String
//!     Dim timestamp As Date
//!     Dim cutoffTime As Date
//!     
//!     cutoffTime = DateAdd("n", -minutes, Now)
//!     
//!     On Error Resume Next
//!     fileNum = FreeFile
//!     Open m_logFile For Input As #fileNum
//!     
//!     Do While Not EOF(fileNum)
//!         Line Input #fileNum, line
//!         
//!         ' Parse timestamp from first field
//!         timestamp = CDate(Left(line, 19))
//!         
//!         If timestamp >= cutoffTime Then
//!             entries.Add line
//!         End If
//!     Loop
//!     
//!     Close #fileNum
//!     On Error GoTo 0
//!     
//!     Set GetRecentEntries = entries
//! End Function
//! ```
//!
//! ### Example 3: Session Manager Module
//!
//! ```vb
//! ' Module: SessionManager
//! ' Manages user sessions with timeout tracking
//!
//! Option Explicit
//!
//! Private Type UserSession
//!     userID As Long
//!     userName As String
//!     loginTime As Date
//!     lastActivity As Date
//!     ipAddress As String
//!     isActive As Boolean
//! End Type
//!
//! Private m_sessions As Collection
//! Private m_timeoutMinutes As Long
//!
//! Public Sub Initialize(timeoutMinutes As Long)
//!     Set m_sessions = New Collection
//!     m_timeoutMinutes = timeoutMinutes
//! End Sub
//!
//! Public Function CreateSession(userID As Long, userName As String, ipAddress As String) As String
//!     Dim session As UserSession
//!     Dim sessionID As String
//!     
//!     ' Generate unique session ID
//!     sessionID = GenerateSessionID()
//!     
//!     session.userID = userID
//!     session.userName = userName
//!     session.loginTime = Now
//!     session.lastActivity = Now
//!     session.ipAddress = ipAddress
//!     session.isActive = True
//!     
//!     m_sessions.Add session, sessionID
//!     
//!     CreateSession = sessionID
//! End Function
//!
//! Public Sub UpdateActivity(sessionID As String)
//!     Dim session As UserSession
//!     
//!     On Error Resume Next
//!     session = m_sessions(sessionID)
//!     
//!     If Err.Number = 0 Then
//!         session.lastActivity = Now
//!         m_sessions.Remove sessionID
//!         m_sessions.Add session, sessionID
//!     End If
//!     On Error GoTo 0
//! End Sub
//!
//! Public Function IsSessionValid(sessionID As String) As Boolean
//!     Dim session As UserSession
//!     Dim minutesIdle As Long
//!     
//!     On Error Resume Next
//!     session = m_sessions(sessionID)
//!     
//!     If Err.Number <> 0 Then
//!         IsSessionValid = False
//!         Exit Function
//!     End If
//!     On Error GoTo 0
//!     
//!     If Not session.isActive Then
//!         IsSessionValid = False
//!         Exit Function
//!     End If
//!     
//!     minutesIdle = DateDiff("n", session.lastActivity, Now)
//!     IsSessionValid = (minutesIdle < m_timeoutMinutes)
//! End Function
//!
//! Public Sub CleanupExpiredSessions()
//!     Dim session As UserSession
//!     Dim sessionID As Variant
//!     Dim minutesIdle As Long
//!     Dim expiredIDs As Collection
//!     
//!     Set expiredIDs = New Collection
//!     
//!     ' Find expired sessions
//!     For Each sessionID In m_sessions
//!         session = m_sessions(sessionID)
//!         minutesIdle = DateDiff("n", session.lastActivity, Now)
//!         
//!         If minutesIdle >= m_timeoutMinutes Then
//!             expiredIDs.Add sessionID
//!         End If
//!     Next sessionID
//!     
//!     ' Remove expired sessions
//!     For Each sessionID In expiredIDs
//!         m_sessions.Remove sessionID
//!     Next sessionID
//! End Sub
//!
//! Public Function GetSessionDuration(sessionID As String) As Long
//!     Dim session As UserSession
//!     
//!     On Error Resume Next
//!     session = m_sessions(sessionID)
//!     
//!     If Err.Number = 0 Then
//!         GetSessionDuration = DateDiff("n", session.loginTime, Now)
//!     Else
//!         GetSessionDuration = 0
//!     End If
//!     On Error GoTo 0
//! End Function
//!
//! Private Function GenerateSessionID() As String
//!     GenerateSessionID = Format(Now, "yyyymmddhhnnss") & "_" & Int(Rnd * 10000)
//! End Function
//! ```
//!
//! ### Example 4: Scheduled Task Runner
//!
//! ```vb
//! ' Class: ScheduledTaskRunner
//! ' Executes tasks on a schedule based on current time
//!
//! Option Explicit
//!
//! Private Type ScheduledTask
//!     taskName As String
//!     lastRun As Date
//!     intervalMinutes As Long
//!     enabled As Boolean
//!     callbackObject As Object
//!     callbackMethod As String
//! End Type
//!
//! Private m_tasks As Collection
//!
//! Private Sub Class_Initialize()
//!     Set m_tasks = New Collection
//! End Sub
//!
//! Public Sub AddTask(taskName As String, _
//!                   intervalMinutes As Long, _
//!                   callbackObj As Object, _
//!                   callbackMethod As String)
//!     Dim task As ScheduledTask
//!     
//!     task.taskName = taskName
//!     task.lastRun = 0
//!     task.intervalMinutes = intervalMinutes
//!     task.enabled = True
//!     Set task.callbackObject = callbackObj
//!     task.callbackMethod = callbackMethod
//!     
//!     m_tasks.Add task, taskName
//! End Sub
//!
//! Public Sub CheckAndRunTasks()
//!     Dim task As ScheduledTask
//!     Dim i As Long
//!     Dim minutesSinceRun As Long
//!     
//!     For i = 1 To m_tasks.Count
//!         task = m_tasks(i)
//!         
//!         If task.enabled Then
//!             If task.lastRun = 0 Then
//!                 ' Never run - execute now
//!                 ExecuteTask task
//!                 task.lastRun = Now
//!                 UpdateTask i, task
//!             Else
//!                 minutesSinceRun = DateDiff("n", task.lastRun, Now)
//!                 
//!                 If minutesSinceRun >= task.intervalMinutes Then
//!                     ExecuteTask task
//!                     task.lastRun = Now
//!                     UpdateTask i, task
//!                 End If
//!             End If
//!         End If
//!     Next i
//! End Sub
//!
//! Private Sub ExecuteTask(task As ScheduledTask)
//!     On Error Resume Next
//!     CallByName task.callbackObject, task.callbackMethod, VbMethod
//!     
//!     If Err.Number <> 0 Then
//!         Debug.Print "Task execution error: " & task.taskName & " - " & Err.Description
//!     End If
//!     On Error GoTo 0
//! End Sub
//!
//! Private Sub UpdateTask(index As Long, task As ScheduledTask)
//!     Dim taskName As String
//!     taskName = task.taskName
//!     
//!     m_tasks.Remove index
//!     m_tasks.Add task, taskName
//! End Sub
//!
//! Public Function GetNextRunTime(taskName As String) As Date
//!     Dim task As ScheduledTask
//!     
//!     On Error Resume Next
//!     task = m_tasks(taskName)
//!     
//!     If Err.Number = 0 Then
//!         If task.lastRun = 0 Then
//!             GetNextRunTime = Now ' Will run immediately
//!         Else
//!             GetNextRunTime = DateAdd("n", task.intervalMinutes, task.lastRun)
//!         End If
//!     End If
//!     On Error GoTo 0
//! End Function
//!
//! Public Sub EnableTask(taskName As String)
//!     Dim task As ScheduledTask
//!     Dim i As Long
//!     
//!     For i = 1 To m_tasks.Count
//!         task = m_tasks(i)
//!         If task.taskName = taskName Then
//!             task.enabled = True
//!             UpdateTask i, task
//!             Exit Sub
//!         End If
//!     Next i
//! End Sub
//!
//! Public Sub DisableTask(taskName As String)
//!     Dim task As ScheduledTask
//!     Dim i As Long
//!     
//!     For i = 1 To m_tasks.Count
//!         task = m_tasks(i)
//!         If task.taskName = taskName Then
//!             task.enabled = False
//!             UpdateTask i, task
//!             Exit Sub
//!         End If
//!     Next i
//! End Sub
//! ```
//!
//! ## Error Handling
//!
//! ```vb
//! ' Now rarely fails, but system clock issues can occur:
//! On Error Resume Next
//! Dim currentTime As Date
//! currentTime = Now
//! If Err.Number <> 0 Then
//!     MsgBox "Unable to get system time: " & Err.Description
//!     ' Use a default or cached value
//! End If
//! On Error GoTo 0
//! ```
//!
//! ## Performance Considerations
//!
//! - Now is a fast function - safe to call frequently
//! - For high-precision timing, use Timer function instead
//! - Does not include milliseconds - precision is to the second
//! - Caching Now value in tight loops can improve performance slightly
//! - System clock access is generally very fast
//! - No performance difference between Now, Date, and Time functions
//!
//! ## Best Practices
//!
//! 1. **Use for timestamps** - Ideal for logging and audit trails
//! 2. **Store in Date variables** - Declare as Date type, not Variant when possible
//! 3. **Format for display** - Use `Format()` function for user-friendly output
//! 4. **Consider time zones** - Now uses local system time, not UTC
//! 5. **Use Timer for precision** - For sub-second timing, use Timer function
//! 6. **Cache in loops** - Store Now once at loop start instead of calling repeatedly
//! 7. **Document timezone** - Make it clear whether times are local or UTC
//! 8. **Use `DateDiff` carefully** - Be aware of daylight saving time changes
//! 9. **Validate before math** - Check for valid dates before date arithmetic
//! 10. **Consider Date vs Now** - Use Date if you only need the date portion
//!
//! ## Comparison with Alternatives
//!
//! | Function | Date Component | Time Component | Use Case |
//! |----------|---------------|----------------|----------|
//! | **Now** | Yes (current) | Yes (current) | Full timestamp |
//! | **Date** | Yes (current) | No (midnight) | Date-only operations |
//! | **Time** | No (12/30/1899) | Yes (current) | Time-only operations |
//! | **Timer** | No | Yes (as Single) | High-precision timing |
//!
//! ## Platform Notes
//!
//! - Available in VBA (Excel, Access, Word, etc.)
//! - Available in VB6
//! - Available in `VBScript`
//! - Uses Windows system clock
//! - Subject to system time zone settings
//! - Affected by daylight saving time changes
//! - No parameters required (parameterless function)
//! - Returns local time, not UTC
//!
//! ## Limitations
//!
//! - Returns local time only (no UTC option)
//! - Precision limited to seconds (no milliseconds)
//! - Subject to system clock changes
//! - Date range: January 1, 100 to December 31, 9999
//! - Can be affected by daylight saving time transitions
//! - No built-in time zone conversion
//! - Depends on accurate system clock
//!
//! ## Related Functions
//!
//! - **Date** - Returns current date (time = midnight)
//! - **Time** - Returns current time (date = 12/30/1899)
//! - **Timer** - Returns seconds since midnight (for precision timing)
//! - **`DateAdd`** - Adds time intervals to dates
//! - **`DateDiff`** - Calculates difference between dates
//! - **Format** - Formats date/time for display
//!
//! ## VB6 Parser Notes
//!
//! Now is a parameterless function that is parsed as a `CallExpression`. This module exists primarily
//! for documentation purposes to provide comprehensive reference material for VB6 developers working
//! with date and time operations, timestamps, logging, and time-based calculations.

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

    #[test]
    fn now_basic() {
        let source = r"
Dim currentTime As Date
currentTime = 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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_parentheses() {
        let source = r"
Dim dt As Date
dt = 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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_if_statement() {
        let source = r#"
If Now > deadline Then
    MsgBox "Overdue"
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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_function_return() {
        let source = r"
Function GetCurrentTime() As Date
    GetCurrentTime = Now
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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_concatenation() {
        let source = r#"
Dim msg As String
msg = "Current time: " & 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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

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

    #[test]
    fn now_msgbox() {
        let source = r#"
MsgBox "Current time is: " & 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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_format() {
        let source = r#"
Dim formatted As String
formatted = Format(Now, "yyyy-mm-dd hh:nn:ss")
"#;
        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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_datediff() {
        let source = r#"
Dim elapsed As Long
elapsed = DateDiff("s", startTime, 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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_class_usage() {
        let source = r"
Private m_timestamp As Date

Public Sub UpdateTimestamp()
    m_timestamp = Now
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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_with_statement() {
        let source = r"
With currentRecord
    .CreatedDate = Now
    .ModifiedDate = Now
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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_array_assignment() {
        let source = r"
Dim timestamps(10) As Date
timestamps(i) = 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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_property_assignment() {
        let source = r"
Set obj = New Logger
obj.Timestamp = 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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_select_case() {
        let source = r#"
Select Case Hour(Now)
    Case 0 To 11
        greeting = "Good morning"
    Case 12 To 17
        greeting = "Good afternoon"
    Case Else
        greeting = "Good evening"
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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_elseif() {
        let source = r"
If x > 0 Then
    y = 1
ElseIf Now > deadline Then
    y = 2
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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_for_loop() {
        let source = r#"
Dim startTime As Date
startTime = Now
For i = 1 To 1000
    DoWork
Next i
MsgBox "Elapsed: " & DateDiff("s", startTime, 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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_do_while() {
        let source = r"
Do While Now < endTime
    ProcessData
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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_do_until() {
        let source = r"
Do Until Now >= targetTime
    WaitForEvent
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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_while_wend() {
        let source = r"
While Now < cutoffTime
    count = count + 1
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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_iif() {
        let source = r#"
Dim status As String
status = IIf(Now > deadline, "Late", "On 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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_comparison() {
        let source = r#"
If DateDiff("h", lastUpdate, Now) > 24 Then
    UpdateData
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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_function_argument() {
        let source = r#"
Call LogEvent("User login", 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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_sql_insert() {
        let source = r#"
sql = "INSERT INTO Events (Timestamp) VALUES (" & Format(Now, "\#mm\/dd\/yyyy hh:nn:ss\#") & ")"
"#;
        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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_year_function() {
        let source = r"
Dim currentYear As Integer
currentYear = Year(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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_month_function() {
        let source = r"
Dim currentMonth As Integer
currentMonth = Month(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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_dateadd() {
        let source = r#"
Dim futureDate As Date
futureDate = DateAdd("d", 7, 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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn now_multiple_calls() {
        let source = r"
Dim start As Date
Dim finish As Date
start = Now
DoWork
finish = 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/now");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}