Forum > General

How do i read from a file then display it to a user?

(1/3) > >>

captian jaster:

--- Code: --- BEGIN
     writeln('Getting Data....');
     assign(file1, 'C:\hydraks\information\info.txt');
     reset(file1);
     delay(2000);
     ClrScr;
     writeln(file1);
     writeln('Press enter to go back');
     readln;
     Goto 1;
   END;
--- End code ---

When the program starts it just closes
what am i doing wrong? Im trying to get it to read from the file then display the file contents

mmab:

--- Quote from: captian jaster on February 18, 2010, 06:21:44 pm ---
--- Code: --- BEGIN
     writeln('Getting Data....');
     assign(file1, 'C:\hydraks\information\info.txt');
     reset(file1);
     delay(2000);
     ClrScr;
     writeln(file1);
     writeln('Press enter to go back');
     readln;
     Goto 1;
   END;
--- End code ---

When the program starts it just closes
what am i doing wrong? Im trying to get it to read from the file then display the file contents

--- End quote ---


--- Code: ---var F:textfile;
     s:string;
begin
if fileexists('C:\hydraks\information\info.txt') then begin
assignfile(F,'C:\hydraks\information\info.txt');
reset(F);
repeat
  s:=readln(F);
   writeln(s);
until eof(F);
closefile(F);
end
else writeln('File not found');
end;
--- End code ---

captian jaster:
I ran your code and got some errors that confused me.
I edited it and got some anistring type error code

--- Code: ---  BEGIN
   if fileexists('C:\hydraks\information\info.txt') then
   BEGIN
     assign(file1, 'C:\hydraks\information/info.txt');
     reset(file1);
     repeat
     s := readln(file1);
     writeln(s)
     until EoF(file1);
     close(file1);
     writeln('Press enter to go back');
     readln;
     Goto 1;
   END
    Else
     BEGIN
       writeln('ERROR');
       writeln(ERROR2);
       writeln('Press enter to go back');
       readln;
       Goto 1;
     END;

   END;
--- End code ---

Zoran:

--- Quote from: captian jaster on February 18, 2010, 07:16:00 pm ---   assign(file1, 'C:\hydraks\information/info.txt');

--- End quote ---

I don't know if it is the only thing, but I can see that you put one slash instead of backslash (.../info.txt - ... \info.txt).

Bart:
This looked odd to me:

--- Code: ---  s := readln(file1);

--- End code ---

Try

--- Code: ---  readln(File1,s);

--- End code ---

(The forwardslash in the filename should not be a problem (at least in the old DOS days all BIOS and DOS functions accepted both \ and / internally as separator))

And please, pretty please, do not use Goto ;-)

Bart

Navigation

[0] Message Index

[#] Next page

Go to full version