’ _Ben_ ’
BC> I want to read the text file line by line and add each lines into the
BC> DBF file. Like readln() in Pascal
[...]
hmmmm... maybe try this (NOT TESTED!)
#include "fileio.ch"
#define DEF_NEW_LINE chr(13)+chr(10)
#define DEF_BUFFER_SIZE 512
#define DEF_EOF (-1)
FUNCTION Read_Test()
local lnHandle
local lcLine
use YOURBASE
lnHandle := fopen('FILE.TXT',FO_READ)
lcLine := ReadLn(lnHandle)
while lcLine != NIL
// save lcLine in new record
dbAppend()
YOURBASE->LINE := lcLine
lcLine := ReadLn(lnHandle)
end
use
RETURN NIL
FUNCTION ReadLn(nHandle)
local lcText := FREADSTR(nHandle,DEF_BUFFER_SIZE)
local lcText2
local lnPos
local lcRet
if empty(lcText)
lcRet = NIL
else
lnPos = at(DEF_NEW_LINE,lcText)
while lnPos == 0
lcText2 = FREADSTR(nHandle,DEF_BUFFER_SIZE)
if empty(lcText2)
lcRet = lcText
lnPos = DEF_EOF
else
lcText += lcText2
lnPos = at(DEF_NEW_LINE,lcText)
endif
end
if lnPos == DEF_EOF
lcRet = lcText
else
fseek(nHandle,lnPos+1-len(lcText),FS_RELATIVE)
lcRet = substr(lcText,1,lnPos-1)
endif
endif
RETURN (lcRet)
/P4D31K/ ÿ
... padzik@writeme.com
--- FMail/386 1.02
---------------
* Origin: - (2:480/76)
|