Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file modes

Status
Not open for further replies.

Delboy14

Programmer
Jun 21, 2001
213
GB
I am trying to update a text file depending on a value entered in a form, the text file's format is
Code:
Name        ID   Approval
Derek Smith 1    Pending
Gopi Chan   2    Approved

The values retrieved from the form will be either Accepted or Rejected for the Approval field and the id eg 1.
I would like to update the Approval field in the text file, so far I have exploded the file by rows (/n) then by tabs (/t) to capture each cell, and I can find the line with the correct ID. How should I change the Approval field ? what file mode should I use?

I have had a few tries but failed so far, should I change the value of the cell then implode the cells and rows and overwrite the previous file? Thanks for any advice
 
The only way you can append a txt file is by adding to the end of it, you can't change text in the middle of a text file like this.

What you will have to do is read the text file into an array or variable until you find the line you want to append, add the new line to the variable and then add the rest of the text file to the variable. Then write the whole lot back to the text file.
BDC.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top