Click to See Complete Forum and Search --> : How to update data in file?


Sunpetch
February 24th, 2000, 03:36 AM
How to update data in File? (AS Text File)
Ex. Like Find and Replace when I would like to change some words.(Eet -->change to --> Eat)

Lothar Haensler
February 24th, 2000, 04:19 AM
I'd read the complete file into memory (if it's not too big), close the file
make the modifications using VB's Replace function,
Open it for writing and rewrite the modified contents.

Actually, I'd rather use a Win32 port of the UNIX stream editor (SED), available from the GNU Site.
Thus, I wouldn't have to write a program.

February 24th, 2000, 05:00 AM
You could try this sort of thing

Dim str as string
Dim filename as string
filename = "C:/myfile.txt"
Open filename for binary as #1
str = Space(LOF(1))
get #1, , str

str = Replace(str, "replacethis", "withthis")
Close #1
Kill filename
Open filename for Output as #1
print #1, Trim(str)
Close #1



Not the best code in the world but it will work.

Sunpetch
February 24th, 2000, 08:20 PM
I 'm not understand about "Kill filename" because when I comment it.The procedue is work.And What is this statement "str = Space(LOF(1))"? It's about the number of line in file right?

Please reply me, Thanks a lot for your procedue.