Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Converting long integer into date
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01054948
Message ID:
01054952
Views:
22
Hi,

This might get you started:
x = CHR(56)+CHR(203)+CHR(49)+CHR(1)
y = STR(StrToLong(x))

  *********************
FUNCTION StrToLong(m.lcLongstr)
  *********************
  * Passed:  4-byte character string (lcLongstr) in low-high ASCII format
  * Returns:  long integer value
  * Example:
  * m.longstr = "1111"
  * m.longval = strtolong(m.longstr)

  LOCAL i, lnRetval, lnAscCode, llIsNeg
  llIsNeg = BITTEST(ASC(m.lcLongstr),7)
  STORE 0 TO m.lnRetval

  FOR m.i = 0 TO 3
    m.lnAscCode = ASC(SUBSTR(m.lcLongstr,i+1,1))
    IF llIsNeg && Negative value
      ** Reverse bits
      m.lnAscCode = BITXOR(m.lnAscCode,0xFF)
    ENDIF
    m.lnRetval  = m.lnRetval + (m.lnAscCode * (2^(i*8)))

  NEXT
  RETURN IIF(llIsNeg,-(m.lnRetval+1),m.lnRetval)
(Function based on code posted by Borislav couple of days ago)
Should be trivial to parse the resulting string into a suitable CTOD() format
HTH,
Viv

>I have a problem convertin data read from a binary file. I have to import these data into a DBF.
>
>Data in the source file where stored by an old DOS based application (may be Pascal or Basic) I know the structure of this file but I have some trouble converting numeric data.
>
>For exemple Date are stored in YYYYMMDD format, as a long (4 bytes)
>
>Exemple :
> ASC(byte1) = 56
> ASC(byte2) = 203
> ASC(byte3) = 49
> ASC(byte4) = 1
>
>This should be converted to a date.... but HOW ??????
>
>Thanks for any answer
Previous
Reply
Map
View

Click here to load this message in the networking platform