Memoread

Memoread

Postby hag » Fri Nov 12, 2010 5: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
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California

Re: Memoread

Postby nageswaragunupudi » Fri Nov 12, 2010 5:45 am

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10630
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Memoread

Postby hag » Fri Nov 12, 2010 6:53 am

Roa
Thanks for the quick response. I am having a problem. Here is my code
Code: Select all  Expand view
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
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California

Re: Memoread

Postby Marc Vanzegbroeck » Fri Nov 12, 2010 10:24 am

Harvey,

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

Code: Select all  Expand view
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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Memoread

Postby nageswaragunupudi » Fri Nov 12, 2010 1:26 pm

Code: Select all  Expand view
cNewText += cLine

should be
Code: Select all  Expand view
cNewText += CRLF + cLine

and
Code: Select all  Expand view
memowrit(cFile,cNewText)

should be
Code: Select all  Expand view
memowrit(cFile,SubStr(cNewText,3))
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10630
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Memoread

Postby hag » Fri Nov 12, 2010 2:56 pm

Thank you both. Perfection.
Thank you
Harvey
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Enrico Maria Giordano and 96 guests