FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Memoread
Posts: 598
Joined: Tue Apr 15, 2008 04:51 PM

Memoread

Posted: Fri Nov 12, 2010 05:14 AM

I have a comma delimited csv file.
I can read the file using memoread().
cText := memoRead(cfile)
I can extract a line using extractLine(cText,@variable)
I can change the line: cline := stuff(cLine,0,0,"0,"). I added a new comma.
but what I can't do is insert the changed line back into the csv file.
Help is appreciated.

Thank you

Harvey
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Memoread

Posted: Fri Nov 12, 2010 05:45 AM

Write the entire modified cText with MEMOWRIT( cFile, cText )

Regards



G. N. Rao.

Hyderabad, India
Posts: 598
Joined: Tue Apr 15, 2008 04:51 PM

Re: Memoread

Posted: Fri Nov 12, 2010 06:53 AM
Roa
Thanks for the quick response. I am having a problem. Here is my code
Code (fw): Select all Collapse
function commas1(cFile)
   local cText := MemoRead(cFile), cLine
   local nLen  := Len( cText )
   local nFrom := 1
   local nVal  := 3 // 3 assign numbers

   While nFrom <= nLen
      cLine  := ExtractLine( cText, @nFrom )

      if NumAt( ",", cLine ) = 2    // number of ","
         cLine := stuff(cLine,0,0,"0,")
         memowrit(cFile,cText)
         skip   
         loop   
      endif
   enddo
       
   nVal := 1    // numbers assigned

   return nVal


Its not picking up each line of the file. Each line has 2 commas. I"m trying to get all lines in the file to have 3 commas.
memowrit only seems to deal with the last line of the cfile.
Thank you

Harvey
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM

Re: Memoread

Posted: Fri Nov 12, 2010 10:24 AM
Harvey,

You need to write the file in one time.
It should be something like this

Code (fw): Select all Collapse
function commas1(cFile)
   local cText := MemoRead(cFile), cLine
   local nLen  := Len( cText )
   local nFrom := 1
   local nVal  := 3 // 3 assign numbers
   local cNewText := ""

   While nFrom <= nLen
      cLine  := ExtractLine( cText, @nFrom )

      if NumAt( ",", cLine ) = 2    // number of ","
         cLine := stuff(cLine,0,0,"0,")
         cNewText += cLine
         skip   
         loop   
      endif
   enddo
   
   memowrit(cFile,cNewText)
   nVal := 1    // numbers assigned

   return nVal


Regards,
Marc
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Memoread

Posted: Fri Nov 12, 2010 01:26 PM
Code (fw): Select all Collapse
cNewText += cLine

should be
Code (fw): Select all Collapse
cNewText += CRLF + cLine

and
Code (fw): Select all Collapse
memowrit(cFile,cNewText)

should be
Code (fw): Select all Collapse
memowrit(cFile,SubStr(cNewText,3))
Regards



G. N. Rao.

Hyderabad, India
Posts: 598
Joined: Tue Apr 15, 2008 04:51 PM

Re: Memoread

Posted: Fri Nov 12, 2010 02:56 PM

Thank you both. Perfection.

Thank you

Harvey

Continue the discussion