Results 1 to 3 of 3

Thread: Bytes To Date

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    2

    Bytes To Date

    Hello
    I needed to save a date to a smart card, so first I had to serialize my 8 byte Date variable to a byte array. I did this with kernel32 copymemory.
    Actually I'm saving just the four last bytes because I dont need the time part.
    My problem is that I cant retrieve the date from the bytes. I tried the following code which results to overflow:
    m_expirationDate = CDate((m_rawBytes(0) * 16777216) + (m_rawBytes(1) * 65536) + (m_rawBytes(2) * 256) + m_rawBytes(3))
    So how can this be done?

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Bytes To Date

    Welcome to the forums.

    Try changing 256 to 256& and see if 1) error goes away and 2) you get what you expect; probably not.

    I suspect that m_rawbytes(2) * 256 is the overflow, 256 is treated as Integer unless ampersand suffix provided.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    2

    Re: Bytes To Date

    The answer was below my eyes:

    Date to bytes:
    CopyMemory dateBytes(0), m_expirationDate, 8

    bytes to Date:
    CopyMemory m_expirationDate, dateBytes(0), 8

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width