Date
data type (by way of fractions of a second)?I'm revisiting VB6 after many years absence, and for the life of me can't remember the things I used to know. I considered putting a memory-leak tag on this, because my memory leaked (hur hur hur).
I found this API call afterwards, and it seems to work:
Declare Sub GetSystemTime Lib "kernel32.dll" (lpSystemTime As SystemTime)
Public Type SystemTime
Year As Integer
Month As Integer
DayOfWeek As Integer
Day As Integer
Hour As Integer
Minute As Integer
Second As Integer
Milliseconds As Integer
End Type
The Date
data type is based on the Double
data type with range checking (min/max Date values) plus a considered epoch. In other words, there's nothing very special about it, especially considering VBA is not a strongly typed language.
If you think of time in a continuum (and IMO you should) then a Double
is a good fit. The precision for double precision floating point where one day = 1 (integer) is effectively nine decimal places. So a value of type Double
(and therefore of type Date
) can comfortably accommodate subsecond values.
However, the problem you face is that temporal functions within VBA (Now
, DateSerial
, DateDiff
, DateAdd
etc) have a minimum granularity of one second. If you use them with your date values stored as Double
with subsecond precision, you will experience rounding to one second. Ditto for user controls etc written for VBA6.
You could write your own implementation of the temporal functions your require, of course (I recall having to implement wrapper classes for StdDataFormat
in order to read/write subsecond SQL Server values without rounding into a MS Data Grid in in VBA) but it will begin to feel like you are rolling your own temporal data type (ouch!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With