I have been tasked with converting an old VB6 program to to C#. One function I have been having trouble porting over is the calculation of a birthdate from a filed that was read from a binary file:
.BirthDate = CDate((CLng(recPatient.birthDateByte2) * 256) +
(recPatient.birthDateByte1 + 366))
The only function I could find that is remotely similar is:
DateTime BirthDate = DateTime.ToDateTime((long)recPatient.birthDateByte2) * 256)
+ (recPatient.birthDateByte1 + 366));
However ToDateTime(long)
just returns an InvalidCastException
.
Now I can build the string manually but I can not find any documentation anywhere on VB6's CDate(long)
.
What am I doing wrong?
Try to use
DateTime.FromOADate((double)recPatient.birthDateByte2 * 256
+ recPatient.birthDateByte1 + 366)
instead.
Here is a small piece of documentation about CDate(long). It is not from MS and not about VB6, but since CDate is part of all VBA implementations I have seen so far, I suspect it won't make a big difference.