problem replaceall with vba code.

M

Maya

Hi.

I wrote a procedure tha scan tx file, look for specific word and replace it
by other.
the problem I have is when the replaceable word is shorter than the
original - I got at the end of the file garbage character. That meen if I
had replaced all the apperance of the word 'red' with the word 'yellow'
which were 9 times at the txt file. I would have at the end of the txt file
21 character. If I replace with a longer word the txt file will be O.K.

I don't want to copy it to a new file.

can anyone help me with that bug.?

Thanks.
 
A

Andi Mayer

Hi.

I wrote a procedure tha scan tx file, look for specific word and replace it
by other.
the problem I have is when the replaceable word is shorter than the
original - I got at the end of the file garbage character. That meen if I
had replaced all the apperance of the word 'red' with the word 'yellow'
which were 9 times at the txt file. I would have at the end of the txt file
21 character. If I replace with a longer word the txt file will be O.K.

I don't want to copy it to a new file.

can anyone help me with that bug.?

Thanks.
how to you read and write that file?

my guess is that you are using get and put?
or you read fixed length?
 
J

John Nurick

Hi Maya,

If editing a text file may change its length, the only way to do it is
to read the existing file and create a new one containing the changes.
 
M

Maya

I manage with the problem, I copy the new txt file to tmp file, and then
'kill' the old txt file and i rename the tmp txt file to the original
name.not elegant but works....

Thanks, Maya
 
J

John Nurick

That's how all text editing programs work under the covers!

I manage with the problem, I copy the new txt file to tmp file, and then
'kill' the old txt file and i rename the tmp txt file to the original
name.not elegant but works....

Thanks, Maya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top