urgent help with text files

  • 19 years ago

    im really stuck with this one. using vb i have created a text file, i can add more records to it but i cannot delete any of these recoreds from the text file using the program i have created. also does anyone know how to edit a record in the file by saving over that record with the new info. thanks alot.
    The Dude

  • 19 years ago

    How are you opening this file when you write to it?  If you open it as Append, it will tack any changes on the end of the existing file.  If you open it as Output, it will overwrite the existing file.  This might be your problem.  John

  • 19 years ago

    im opening it as append. if i open it as output wont it write over all the records? the delting is really the main thing but thanks.

  • 19 years ago

    To delete a line, you'll have to read the whole file into a variable, and output the whole file again... just missing out the line you don't want any more.

  • 19 years ago

    how do i do that? and have u got any info on editing a record?

  • 19 years ago

    To find out how to save the contents of a text box to a file, click here.


    To find out how to load the contents of a text box to a file, click here.


    Regarding records, how exactly are you saving them?

  • 19 years ago

    this is how im saving them:
    open app.path & "\StaffInfo.txt" for append as #1
    write #1, staff.name, staff.dateofbirth
    close #1


    i know how to save and how to load, i just cant overwrite

  • 19 years ago

    Well... what you do is Load it, to a Replace on the line you want, ie


    'load the file into sContents, then...
    sContents=Replace(sContents,"my line" & vbCrLf, "")
    'then save the whole lot to the file again (WITHOUT using append)

  • 19 years ago

    why not output them all into a database?


    that way you can delete records very easily and output the results to a textfile if that's what's needed?

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are only 3 numbers of interest to a computer scientist: 1, 0 and infinity”