Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
delete procedure Posted by sexyderry on 30 Apr 2003 at 11:16 AM
can any one help with a delete procedure please. it is AS coursework and i cant get it to work it compiles but gives a run time error.

begin
clrscr;
assign (pupilfile,'n:pupil.dat');
reset (pupilfile);
writeln ('existing file');
writeln;writeln;writeln;
writeln ('name':15,' Candidate':9,'year':6,'mark':5);
writeln (' ':15,' number ':9,' ':6,' ':5);

writeln;
writeln;
readln;
while not eof (pupilfile) do
begin
read (pupilfile,temp);
writeln (temp.name:15,temp.cand_no:9,temp.year:6,temp.mark:5);
end;

reset (pupilfile);
writeln ('enter candidate number to be deleted');
readln (n);
position:=0;
while not eof (pupilfile) do
begin
read (pupilfile,temp);
position:=(position+1);
if (temp.cand_no=n) then begin
clrscr;
writeln (temp.name:15,temp.cand_no:9,temp.year:6,temp.mark:5);
writeln;writeln;
writeln ('is this the record to be deleted: ');
readln (ans);
if (ans='y') or (ans='Y') then begin
seek (pupilfile,filesize(pupilfile)-1);
truncate (pupilfile);
end;
reset (pupilfile);
clrscr;
writeln ('name':15,'year':10,'mark':10);
writeln;

while not eof (pupilfile) do
begin
read (pupilfile,temp);
writeln (temp.name:15,temp.cand_no:8,temp.year:6,temp.mark:5);
end;
close (pupilfile);

end;
end;

??????????????????????????????? thanks for your help...


Report
Re: delete procedure Posted by roland48 on 2 May 2003 at 2:46 PM
: can any one help with a delete procedure please. it is AS coursework and i cant get it to work it compiles but gives a run time error.
:
: begin
: clrscr;
: assign (pupilfile,'n:pupil.dat');
: reset (pupilfile);
: writeln ('existing file');
: writeln;writeln;writeln;
: writeln ('name':15,' Candidate':9,'year':6,'mark':5);
: writeln (' ':15,' number ':9,' ':6,' ':5);
:
: writeln;
: writeln;
: readln;
: while not eof (pupilfile) do
: begin
: read (pupilfile,temp);
: writeln (temp.name:15,temp.cand_no:9,temp.year:6,temp.mark:5);
: end;
:
: reset (pupilfile);
: writeln ('enter candidate number to be deleted');
: readln (n);
: position:=0;
: while not eof (pupilfile) do
: begin
: read (pupilfile,temp);
: position:=(position+1);
: if (temp.cand_no=n) then begin
: clrscr;
: writeln (temp.name:15,temp.cand_no:9,temp.year:6,temp.mark:5);
: writeln;writeln;
: writeln ('is this the record to be deleted: ');
: readln (ans);
: if (ans='y') or (ans='Y') then begin
: seek (pupilfile,filesize(pupilfile)-1);
: truncate (pupilfile);
: end;
: reset (pupilfile);
: clrscr;
: writeln ('name':15,'year':10,'mark':10);
: writeln;
:
: while not eof (pupilfile) do
: begin
: read (pupilfile,temp);
: writeln (temp.name:15,temp.cand_no:8,temp.year:6,temp.mark:5);
: end;
: close (pupilfile);
:
: end;
: end;
:
: ??????????????????????????????? thanks for your help...
:
:
:

Take a look in your help-file to get the sense of your runtime-error!
I gues there is an IO-Error . You are not shure, if the requested file
exists and you make a reset on an file just opend.
Use the local compiler-switch {$I-)... Code ...{SI+} to trap your
error and get the meaning of IOResult!




Report
Re: delete procedure Posted by Phat Nat on 3 May 2003 at 7:51 AM
: can any one help with a delete procedure please. it is AS coursework and i cant get it to work it compiles but gives a run time error.
:
: begin
: clrscr;
: assign (pupilfile,'n:pupil.dat');
: reset (pupilfile);
: writeln ('existing file');
: writeln;writeln;writeln;
: writeln ('name':15,' Candidate':9,'year':6,'mark':5);
: writeln (' ':15,' number ':9,' ':6,' ':5);
:
: writeln;
: writeln;
: readln;
: while not eof (pupilfile) do
: begin
: read (pupilfile,temp);
: writeln (temp.name:15,temp.cand_no:9,temp.year:6,temp.mark:5);
: end;
:
: reset (pupilfile);
: writeln ('enter candidate number to be deleted');
: readln (n);
: position:=0;
: while not eof (pupilfile) do
: begin
: read (pupilfile,temp);
: position:=(position+1);
: if (temp.cand_no=n) then begin
: clrscr;
: writeln (temp.name:15,temp.cand_no:9,temp.year:6,temp.mark:5);
: writeln;writeln;
: writeln ('is this the record to be deleted: ');
: readln (ans);
: if (ans='y') or (ans='Y') then begin
: seek (pupilfile,filesize(pupilfile)-1);
: truncate (pupilfile);
: end;
: reset (pupilfile);
: clrscr;
: writeln ('name':15,'year':10,'mark':10);
: writeln;
:
: while not eof (pupilfile) do
: begin
: read (pupilfile,temp);
: writeln (temp.name:15,temp.cand_no:8,temp.year:6,temp.mark:5);
: end;
: close (pupilfile);
:
: end;
: end;
:
: ??????????????????????????????? thanks for your help...


What are all your variables (mainly the TEMP variable) declared as ?

Phat Nat


Report
Re: delete procedure Posted by sexyderry on 3 May 2003 at 1:28 PM
: : can any one help with a delete procedure please. it is AS coursework and i cant get it to work it compiles but gives a run time error.
: :
: : begin
: : clrscr;
: : assign (pupilfile,'n:pupil.dat');
: : reset (pupilfile);
: : writeln ('existing file');
: : writeln;writeln;writeln;
: : writeln ('name':15,' Candidate':9,'year':6,'mark':5);
: : writeln (' ':15,' number ':9,' ':6,' ':5);
: :
: : writeln;
: : writeln;
: : readln;
: : while not eof (pupilfile) do
: : begin
: : read (pupilfile,temp);
: : writeln (temp.name:15,temp.cand_no:9,temp.year:6,temp.mark:5);
: : end;
: :
: : reset (pupilfile);
: : writeln ('enter candidate number to be deleted');
: : readln (n);
: : position:=0;
: : while not eof (pupilfile) do
: : begin
: : read (pupilfile,temp);
: : position:=(position+1);
: : if (temp.cand_no=n) then begin
: : clrscr;
: : writeln (temp.name:15,temp.cand_no:9,temp.year:6,temp.mark:5);
: : writeln;writeln;
: : writeln ('is this the record to be deleted: ');
: : readln (ans);
: : if (ans='y') or (ans='Y') then begin
: : seek (pupilfile,filesize(pupilfile)-1);
: : truncate (pupilfile);
: : end;
: : reset (pupilfile);
: : clrscr;
: : writeln ('name':15,'year':10,'mark':10);
: : writeln;
: :
: : while not eof (pupilfile) do
: : begin
: : read (pupilfile,temp);
: : writeln (temp.name:15,temp.cand_no:8,temp.year:6,temp.mark:5);
: : end;
: : close (pupilfile);
: :
: : end;
: : end;
: :
: : ??????????????????????????????? thanks for your help...
:
:
: What are all your variables (mainly the TEMP variable) declared as ?
:
: Phat Nat
:
:
:
they are all in the glabal variable box.

all the candidates profiles are read into a record, and pupilfile is read into temp.

type a=record
name_address:string[15];
candno_address: integer;
addressline:string[20];
town:string[10];
postcode:string[6];
end;

type p=record
name : string[15];
cand_no:integer;
year : integer;
mark : integer;
new_grade:char;
sub_ref_code:string[5];

var temp : p;
pupilfile : file of p;
end;
Report
Re: delete procedure Posted by Phat Nat on 3 May 2003 at 5:12 PM
This message was edited by Phat Nat at 2003-5-3 17:13:40

: can any one help with a delete procedure please. it is AS coursework and i cant get it to work it compiles but gives a run time error.
:
begin
clrscr;
assign (pupilfile,'n:pupil.dat');
reset (pupilfile);
writeln ('existing file');
writeln;writeln;writeln;
writeln ('name':15,' Candidate':9,'year':6,'mark':5);
writeln ('    ':15,' number   ':9,'    ':6,'    ':5);

writeln;
writeln;
readln;
while not eof (pupilfile) do
      begin
      read (pupilfile,temp);
      writeln (temp.name:15,temp.cand_no:9,temp.year:6,temp.mark:5);
      end;

reset (pupilfile);
writeln ('enter candidate number to be deleted');
readln (n);
position:=0;

while not eof (pupilfile) do
begin
     read (pupilfile,temp);
     position:=(position+1);
     if (temp.cand_no=n) then
     begin
          clrscr;
          writeln (temp.name:15,temp.cand_no:9,temp.year:6,temp.mark:5);
          writeln;writeln;
          writeln ('is this the record to be deleted: ');
          readln (ans);
          if (ans='y') or (ans='Y') then
          begin
               seek (pupilfile,filesize(pupilfile)-1);
               truncate (pupilfile);
          end;
          reset (pupilfile);
          clrscr;
          writeln ('name':15,'year':10,'mark':10);
          writeln;

          while not eof (pupilfile) do
          begin
               read (pupilfile,temp);
               writeln (temp.name:15,temp.cand_no:8,temp.year:6,temp.mark:5);
          end;
          close (pupilfile);
     end; 
end;   { before it can exit here, it checks again up above }


Your problem is that you are closing your file and then it checks it again. Since the file is closed, it gives a runtime error when it checks for the end of the file.

          {...}
          while not eof (pupilfile) do
          begin
               read (pupilfile,temp);
               writeln (temp.name:15,temp.cand_no:8,temp.year:6,temp.mark:5);
          end;
     end; 
     close (pupilfile);     { Move the close call here }
end;


This should do it.

Phat Nat



Report
Re: delete procedure Posted by sexyderry on 4 May 2003 at 6:49 AM
: This message was edited by Phat Nat at 2003-5-3 17:13:40

: : can any one help with a delete procedure please. it is AS coursework and i cant get it to work it compiles but gives a run time error.
: :
:
: begin
: clrscr;
: assign (pupilfile,'n:pupil.dat');
: reset (pupilfile);
: writeln ('existing file');
: writeln;writeln;writeln;
: writeln ('name':15,' Candidate':9,'year':6,'mark':5);
: writeln ('    ':15,' number   ':9,'    ':6,'    ':5);
: 
: writeln;
: writeln;
: readln;
: while not eof (pupilfile) do
:       begin
:       read (pupilfile,temp);
:       writeln (temp.name:15,temp.cand_no:9,temp.year:6,temp.mark:5);
:       end;
: 
: reset (pupilfile);
: writeln ('enter candidate number to be deleted');
: readln (n);
: position:=0;
: 
: while not eof (pupilfile) do
: begin
:      read (pupilfile,temp);
:      position:=(position+1);
:      if (temp.cand_no=n) then
:      begin
:           clrscr;
:           writeln (temp.name:15,temp.cand_no:9,temp.year:6,temp.mark:5);
:           writeln;writeln;
:           writeln ('is this the record to be deleted: ');
:           readln (ans);
:           if (ans='y') or (ans='Y') then
:           begin
:                seek (pupilfile,filesize(pupilfile)-1);
:                truncate (pupilfile);
:           end;
:           reset (pupilfile);
:           clrscr;
:           writeln ('name':15,'year':10,'mark':10);
:           writeln;
: 
:           while not eof (pupilfile) do
:           begin
:                read (pupilfile,temp);
:                writeln (temp.name:15,temp.cand_no:8,temp.year:6,temp.mark:5);
:           end;
:           close (pupilfile);
:      end; 
: end;   { before it can exit here, it checks again up above }
: 

:
: Your problem is that you are closing your file and then it checks it again. Since the file is closed, it gives a runtime error when it checks for the end of the file.
:
:
:           {...}
:           while not eof (pupilfile) do
:           begin
:                read (pupilfile,temp);
:                writeln (temp.name:15,temp.cand_no:8,temp.year:6,temp.mark:5);
:           end;
:      end; 
:      close (pupilfile);     { Move the close call here }
: end;
: 

:
: This should do it.
:
: Phat Nat
:
:
:
:
I CANNOT BELIEVE I DIDNT SEE THAT!! THANKS ALOT NAT. YOU HERO!! LOL!! CHEERS FOR THAT.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.