Text File Editing Problem

I have created a text(.txt) file using the code below. I have to edit and
change the value of "Numberofbooks:= ?' .
How can I do this without altering (deleting) the rest of the file


Program Library;
Var
 ArchBiblio:Text;
 Code            :String[10];
 Namebook        :String[50];
 Numberofbooks   :String[3];

Begin
  Assign(ArchBiblio,'BIBLIOTEC.TXT');
  Rewrite(ArchBiblio);

     Code       :='0001';
     WriteLn(ArchBiblio,Code);
     Namebook     :='Chess Games';
     WriteLn(ArchBiblio,Namebook);
     Numberofbooks:='3';
     WriteLn(ArchBiblio,Numberofbooks);

     Writeln(ArchBiblio);

     Code       :='0002';
     WriteLn(ArchBiblio,Code);
     Namebook     :='Hello America';
     WriteLn(ArchBiblio,Namebook);
     Numberofbooks:='4';
     WriteLn(ArchBiblio,Numberofbooks);

 Close(ArchBiblio);

End.
trinas1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VIBESPROCommented:
use your code above to make the file first then try this:  Let me know if it works right...


Program Library_2;
Var
 ArchBiblio:Text;
 Code            :String[10];
 Namebook        :String[50];
 Numberofbooks   :String[3];

Begin
  Assign(ArchBiblio,'BIBLIOTEC.TXT');
  Reset(ArchBiblio);

{ first get the data that was stored in the file }

     Read(ArchBiblio,Code);
     Read(ArchBiblio,Namebook);
     Read(ArchBiblio,Numberofbooks);
     Read(ArchBiblio);

 Close(ArchBiblio);
{ now close the file and reopen it to write data to it }

  Assign(ArchBiblio,'BIBLIOTEC.TXT');
  Rewrite(ArchBiblio);

     WriteLn(ArchBiblio,Code);
     WriteLn(ArchBiblio,Namebook);

{ Here is where you want to make the  
  change }
     Numberofbooks:='your choice';
     WriteLn(ArchBiblio,Numberofbooks);

     Writeln(ArchBiblio);

 Close(ArchBiblio);

I understand what you want to do.  You want to change one line the file without actually changing anything else!

That cannot be done without rewriting the file.  You must first store the data of the file into your variables as shown above then make the neccesary changes you wish and write it back to the file.

End.
0
bakry99Commented:
Hi Trinas1
  You have to create a new file and then
read from old file ('BIBLIOTEC.TXT'),
Write to the new file created, and  when you read  'Numberofbooks' you change it if you like.
  Try This:
Program Library;
Var
 ArchBiblio, Temp: Text;
 Code            : String[10];
 Namebook        : String[50];
 Numberofbooks   : String[3];
Begin
  Assign(ArchBiblio,'BIBLIOTEC.TXT');  
  Assign(Temp, 'TempFile.Txt');
  Reset(ArchBiblio);
  ReWrite(Temp);
  While Not Eof(ArchBiblio) do
  Begin
     Readln(ArchBiblio, Code);
     Writeln(Temp, Code);
     Readln( ArchBiblio, NameBook);
     Writeln(Temp, NameBook);
     Readln(ArchBiblio, Numberofbooks);
     Writeln('The book is : ', BookName);
     Write('Howmany Books : ');
     Readln(Numberofbooks);
     Writeln(Temp, Numberofbooks);
     Readln(ArchBiblio );
     Writeln(Temp);
   end;{Of While}  
   Close(Temp);
   Close(ArchBiblio);
   Erase(ArchBiblio);
   Rename(Temp,'BIBLIOTEC.TXT');
end.

          Bakry
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
trinas1Author Commented:
Thank`s Bakry
 
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.