Home > Archive > Programming with dBASE > February 2006 > Am I doing this correctly?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Am I doing this correctly?
Rick Gearardo

2006-02-10, 9:23 am

f = new file
f.open("myfile")
do while .not. f.eof()
if f.read(1) = chr(34) //double quote mark
fwrite(" ") //blank space
endif
enddo

If I put a message box in the loop I see the correct characters but the
write command is not replacing anything.

TIA,

Rick


Ronnie MacGregor

2006-02-10, 9:23 am


On Fri, 10 Feb 2006 07:32:22 -0600
Rick Gearardo said :

> f = new file
> f.open("myfile")
> do while .not. f.eof()
> if f.read(1) = chr(34) //double quote mark
> fwrite(" ") //blank space
> endif
> enddo
>
> If I put a message box in the loop I see the correct characters but the
> write command is not replacing anything.


Hi Rick

Apart from this corrected typo :

f.write(" ") //blank space

If you write to the file like this, you overwrite the character following your
double quote mark. Is this what you want ?

My approach would be to read from the file, appending to a string variable, and
then write the modified string back in one step. I would also close the read
file and open afresh to do the write, but that's just habit, it's not to say
that it can't be done with one open file, but if you do it your way then you
are continually going to have to be very careful where the file pointer is,
putting it back to the beginning for a complete file overwrite, moving back one
character to overwrite it, and you also need to consider the case where
overwritten total text file length is shorter than the original.

So I would tend to :
Read file and build string
Close file
Delete file
Create new file

Less prone to problems ?

--
Ronnie MacGregor
Scotland

Ronnie at
dBASEdeveloper
dot co dot uk

www.dBASEdeveloper.co.uk



Rick Gearardo

2006-02-10, 1:23 pm

Thanks Ronnie,

Rick
>
> Hi Rick
>
> Apart from this corrected typo :
>
> f.write(" ") //blank space
>
> If you write to the file like this, you overwrite the character following
> your
> double quote mark. Is this what you want ?
>
> My approach would be to read from the file, appending to a string
> variable, and
> then write the modified string back in one step. I would also close the
> read
> file and open afresh to do the write, but that's just habit, it's not to
> say
> that it can't be done with one open file, but if you do it your way then
> you
> are continually going to have to be very careful where the file pointer
> is,
> putting it back to the beginning for a complete file overwrite, moving
> back one
> character to overwrite it, and you also need to consider the case where
> overwritten total text file length is shorter than the original.
>
> So I would tend to :
> Read file and build string
> Close file
> Delete file
> Create new file
>
> Less prone to problems ?
>
> --
> Ronnie MacGregor
> Scotland
>
> Ronnie at
> dBASEdeveloper
> dot co dot uk
>
> www.dBASEdeveloper.co.uk
>
>
>



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com