Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can FoxPro do Biniary?
Message
From
19/01/2000 12:11:16
 
 
To
19/01/2000 10:02:49
Steve Summers
Pima County Superior Court
Tucson, Arizona, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00319871
Message ID:
00319985
Views:
15
Hi Steve.

>I have a binary file created from a wang db. Is there a way VFP can read the file directly into a VFP table. I have the structure of the file and several fields are packed decimal.

VFP can't read the file directly using a single command, so you'll need to open and process the file using low-level file functions like FOPEN and FREAD. Typically, you'll use code like this:
lnHandle = fopen(NameOfDataFile)
do while not feof(lnHandle)
  lcRecord = fread(lnHandle, NumberOfBytesPerRecord)
  lcField1 = left(lcRecord, NumberofBytesInFirstField)
  lcField2 = substr(lcRecord, StartPositionOfSecondField, NumberofBytesInSecondField)
  insert into NameOfVFPTable values (lcField1, lcField2)
enddo
You can do any data conversion of the fields you need (eg. character to number or date) before inserting into the VFP table.

The format for packed decimal (BCD) values varies, but here's the code I used to convert BCD strings to a numeric value. In the app this code comes from, numbers were coded as follows:

Value = +1234
Hex representation: 01 23 4C

Value = -1234
Hex representation: 01 23 4D

Hence the check in this code for "C" to indicate a positive value.
lparameters tcValue
local lcValue, ;
  lnI, ;
  lnChar
#define ccPOSITIVE 'C'
lcValue = ''
for lnI = 1 to len(tcValue)
  lnChar  = asc(substr(tcValue, lnI, 1))
  lcValue = lcValue + right(transform(lnChar, '@0'), 2)
next lnI
lnValue = val(left(lcValue, len(lcValue) - 1)) * ;
  iif(right(lcValue, 1) = ccPOSITIVE, 1, -1)
return lnValue
Hope this helps.

Doug
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform