Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Read Binary Data using foxpro.
Message
From
30/10/2002 05:41:49
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00716782
Message ID:
00716801
Views:
16
>I have a data file that was written in Visual Basic. The file is a binary file. It contains multiple row with 258 columns of long type data. Each colunm is of long type that is.
>
>How can I read this file into Foxpro. Using fgets, fread, or any other command.
>
>Thanks
>
>Tim Boccaleri

Tim,
I'd go with fopen, fread. However where would you read it ? 258 columns is above table columns limit. You might read into array or split into 2 tables.
ie: read into array (assuming rowcount lte 252) :
local handle, lnSize, lnCols, lnRows, ix, jx
lnCols = 258
handle = fopen('myexternalfile.ext')
lnSize = fseek(handle,0,2) && Get size
=fseek(handle,0,0) && Rewind
lnRows = int(lnSize/(lnCols*4))
local array arrData[lnRows,lnCols]
for ix=1 to lnRows
  for jx=1 to lnCols
    arrData[ix,jx] = Char2Num(fread(handle,4),4)
  endfor
endfor
=fclose(handle)

function Char2Num
Lparameters tcStr, tnSize
tnSize = Iif(Empty(tnSize),1,tnSize)
Local lnNum,ix
tcStr = Padr(tcStr,tnSize,Chr(0))
lnNum=0
For ix=1 To tnSize
  lnNum = lnNum + Asc(Substr(tcStr,ix,1))*(256^(ix-1))
Endfor
Return lnNum
Endproc
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform