I have confirmed that the following VBA code works just fine.
Dim mydate As Date
mydate = Date
Open "C:\Windows\Temp\dlctest.data" For Binary Access Write As #1
Put #1, , mydate
Close #1
Open "C:\Windows\Temp\dlctest.data" For Binary Access Read As #1
Get #1, , mydate
Close #1
MsgBox "MyDate = " & mydate
But the actual file I want to work with was created by a separate product and has multiple entries in it--each entry with multiple date, time, and decimal fields and other single-byte character fields. The entries are only fixed length (329 bytes) after the header record--which is shorter (94 bytes).
I would like to read and save the header, then read each entry in its entirety--afterwards, parsing out the fields as needs be. But, that is my question...
What is the best way to take a binary date, e.g., out of a byte array, and turn it back into a valid VBA date?
For testing purposes, I tried creating Type blocks for the two record types.
Private Type schedulerHeader ' reclen = 94
HeaderVersion(25 - 1) As Byte
HeaderFiller1(69 - 1) As Byte
End Type
Private Type schedulerEntry ' reclen = 329
EntryFiller1(6 - 1) As Byte
EntryName(100 - 1) As Byte
EntryEvent(8 - 1) As Byte
EntryBegStamp(15 - 1) As Byte
EntryOptions(7 - 1) As Byte
EntryFiller2(14 - 1) As Byte
EntryRunStamp(15 - 1) As Byte
EntryEndStamp(15 - 1) As Byte
EntryNxtStamp(15 - 1) As Byte
EntryFiller3(126 - 1) As Byte
EntryTag(8 - 1) As Byte
End Type
But after reading from the file, all byte arrays were empty. I even tried initializing all of the byte arrays before reading from the file.
For i = 0 To UBound(myHeader.HeaderVersion)
myHeader.HeaderVersion(i) = 32
Next i
What is the better way to read this file--or what is wrong with the above method?