Page 2 of 5
Need to open and read text file.
Posted: Wed May 29, 2013 4:01 pm
by NickSteel
Could I trouble you one more time? I wanted to save cLine to a file while it processed.
Code: Select all
If nArquivo # -1
Do While !lEof .and. ctr<10
cLine := CharRem( Chr(26), ReadLine(nArquivo,LINEBUFF) )
Aadd(aLine,cLine)
msginfo(cline)
fwrite(outfile,cLine)
ctr++
Enddo
Endif
This doesn't seem to work. I am having trouble with fwrite. Don't know what I'm doing wrong.
[u]Moderator Notes[/u] (Pablo César) wrote:Message re-edited to put the tag Code: Select all
[/b]
Please note tag CODE is recommended when it is source code samples posted for better reading.[/color][/quote]
Re: Need to open and read text file.
Posted: Wed May 29, 2013 4:17 pm
by Pablo César
NickSteel wrote:Could I trouble you one more time? I wanted to save cLine to a file while it processed.
No problem.
Code: Select all
nFhandle2:= Fcreate( 'File.txt', 0 )
If nFhandle2 > 2
Do While !lEof .and. ctr<10
cLine := CharRem( Chr(26), ReadLine(nArquivo,LINEBUFF) )
Aadd(aLine,cLine)
FWriteLine( nFhandle2, cline )
ctr++
Enddo
Endif
Static Function FWriteLine( nHandle, cString )
Fwrite( nHandle, cString )
Fwrite( nHandle, chr(13) )
Fwrite( nHandle, chr(10) )
Return Nil
You can use FWriteLine for many files, depending always nFhandle from Fcreate you do.
Re: Need to open and read text file.
Posted: Wed May 29, 2013 5:15 pm
by NickSteel
Wow. I just processed a 2400 line file in a 6 seconds on an old dual core laptop! Had to make LINEBUFF very large, but it worked like a champ.
You've made my day.

Re: Need to open and read text file.
Posted: Wed May 29, 2013 5:42 pm
by Pablo César
Remember: these functions are in LOW LEVEL. The best way to access files and read strings, also binaries. Study all these low level functions, very very useful.
I am happy to be helpfull...

Re: Need to open and read text file.
Posted: Thu May 30, 2013 9:26 am
by NickSteel
Since you're a whiz with low level functions, do you have suggestions for parsing the tab delimited data while it is in the buffer? I've been searching sites and have read that it is much faster than writing to a string variable and parsing that. What I wish to do is read lines from a Primavera P6 XER export file (text delimited with tabs), select some "fields" of data and update existing DBF files. Your code is lightning fast at accessing the input text, but I haven't been able to find any existing parsing functions.
Your aid is very appreciated.
Need to open and read text file.
Posted: Thu May 30, 2013 1:03 pm
by Pablo César
I learned much including low level functions, with
this guy. There is also good and friendly atmosphere in Clipper on Line forum.
Could you post some sample file in you next post ? Just to see it in hexadecimal editor and check which exactly is needing for.
For parsing characters even in the buffer it could be done. You will find an example at STRU.prg (
here it is the package project, without executable file) and look up for "
Function Le_Variavel(cBuff)"
Re: Need to open and read text file.
Posted: Thu May 30, 2013 2:25 pm
by srvet_claudio
Pablo César wrote:NickSteel wrote:What is easy way to display the array?
I usually use DebugMSG function from our colleague Marek. Hereunder is:
Code: Select all
Function DebugMSG
Local i, aTemp := {}
For i := 1 to pcount()
aadd( aTemp, hb_PValue(i))
Next i
MsgBox(hb_valtoexp(aTemp), "Helpful informations")
Return Nil
Put in you code and call this function like this:
DebugMSG(aLine)
This is very clever code! I know it will solve my problem, as it reads the source file line by line.
Thank you and glad to know it has been helpful to you...
Since version HMG.3.1.3
Code: Select all
MsgDebug ( xData1, xData2, ... ) --> Accepts as a parameters any data type, elements or objects.
Returns a string with the message displayed on the screen.
Example:
Num := 10
aData := { "Number", 38, "aRGB", YELLOW, "Hello" }
cMsg := MsgDebug ( TIME(), aData, {|| NIL}, Num == 3 )
Re: Need to open and read text file.
Posted: Thu May 30, 2013 2:27 pm
by NickSteel
Can't attach txt or xer files.
Re: Need to open and read text file.
Posted: Thu May 30, 2013 2:47 pm
by Pablo César
srvet_claudio wrote:Since version HMG.3.1.3
Code: Select all
MsgDebug ( xData1, xData2, ... ) --> Accepts as a parameters any data type, elements or objects.
Returns a string with the message displayed on the screen.
Example:
Num := 10
aData := { "Number", 38, "aRGB", YELLOW, "Hello" }
cMsg := MsgDebug ( TIME(), aData, {|| NIL}, Num == 3 )
Dr. Soto Thanks for reminding us! Had not stopped to see such a function.
Nick wrote:Can't attach txt or xer files.
Try to attach using WinRar. Probably it due for forum security reasons.
Re: Need to open and read text file.
Posted: Thu May 30, 2013 2:49 pm
by NickSteel
My source file.