CDate transfer (long) from VB6 to C #

I am tasked with converting the old VB6 program to C #. One of the functions I had to deal with was calculating the date of birth from a file that was read from a binary file:

.BirthDate = CDate((CLng(recPatient.birthDateByte2) * 256) + (recPatient.birthDateByte1 + 366)) 

The only function I could find remotely similar:

 DateTime BirthDate = DateTime.ToDateTime((long)recPatient.birthDateByte2) * 256) + (recPatient.birthDateByte1 + 366)); 

However, ToDateTime(long) just returns an InvalidCastException .

Now I can create the line manually, but I can not find any documentation anywhere on VB6 CDate(long) .

What am I doing wrong?

+4
source share
2 answers

Try using

  DateTime.FromOADate((double)recPatient.birthDateByte2 * 256 + recPatient.birthDateByte1 + 366) 

instead.

Here is a small part of the documentation for CDate (long). This is not from MS, not from VB6, but since CDate is part of all the VBA implementations I have seen so far, I suspect it will not make much difference.

+5
source

Old VB6 data type becomes System.Int32 or just int in C #

long in C # - System.Int64

double - System.double, which is a 64-bit floating point

0
source

All Articles