CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2000
    Location
    Thailand
    Posts
    5

    How to update data in file?

    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)


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: How to update data in file?

    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.


  3. #3
    Guest

    Re: How to update data in file?

    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.


  4. #4
    Join Date
    Feb 2000
    Location
    Thailand
    Posts
    5

    Re: How to update data in file?

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured