日期变量在 VB 6.0 中显示默认值为 00:00:00

Date Variable shows default value as 00:00:00 in VB 6.0

我在 Visual Basic 6.0 中将一个变量定义为 Date,如下所示:

Dim procDate as Date

它工作正常并接受从数据库中导出的日期。

今天,我收到错误消息,显示此变量的数据类型不匹配。 当我检查它的默认值时,它显示 00:00:00 这是没有日期值的时间格式。

这可能是什么原因?

您似乎在为 ProcDate 分配一个字符串。

这是分配 Format 生成的字符串的规则。它被称为 Let 强制。

String to Date

If the source string can be interpreted as either a date/time, time, or date value (in that precedence order) according to the host-defined regional settings, the value is converted to a Date.

Otherwise, if the source string can be interpreted as a number or currency value according to the host-defined regional settings, and the resulting value is within the magnitude range of Double, the value is converted to the nearest representable Double value, and then this value is Let-coerced to Date. If this coerced value is within the range of Date, the result is the date value.

If the source string could not be interpreted as a date/time, time, date, number or currency value, runtime error 13 (Type mismatch) is raised. If the conversion to Double resulted in an overflow, runtime error 13 (Type mismatch) is raised instead of the runtime error 6 (Overflow) that would otherwise be raised.