runtime error as IOresult<>0

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2009
Posts: 5
Reputation: amazing_grace is an unknown quantity at this point 
Solved Threads: 0
amazing_grace amazing_grace is offline Offline
Newbie Poster

runtime error as IOresult<>0

 
0
  #1
Nov 6th, 2009
ok, when the user types in a non-exist file name, the program simply shut down. i dont know what happen

procedure set_up;
begin
write('file');readln(file);
assign(f,file); reset(f);
{$I-}if IOresult<>0 then writeln('NO File....');
close(f);{$I+}
end;
....
{this is the main program}
begin
setup;
end

this proceure is called in the main program ,yet, runtime error occurs and the screen just flashes out. it works perfectly when i type in the correct filename. i need your help!!!

grace
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 10
Reputation: quaifp1 is an unknown quantity at this point 
Solved Threads: 3
quaifp1 quaifp1 is offline Offline
Newbie Poster
 
0
  #2
Nov 6th, 2009
Hi,

You must put the IO Checking off flag before the assign statement otherwise the exception occurs before you can check it;
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 465
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 113
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training
 
0
  #3
Nov 8th, 2009
catch the reset(filevar)
  1. {$I-}
  2. reset(f);
  3. {$I+}
  4. if ioresult <> 0 then writeln('error when trying to open the file');
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC