VB6 Date data type: precision and formatting

我是研究僧i 提交于 2019-12-12 09:44:01

问题


  1. How precise is the VB6 Date data type (by way of fractions of a second)?
  2. How to format it to show 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

回答1:


1) Seconds only, and

2) There's no way.




回答2:


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!)




回答3:


I think that the Date Datatype in VB6 can not handle fractions of a second.



来源:https://stackoverflow.com/questions/186622/vb6-date-data-type-precision-and-formatting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!