Discussion:
Help with text file reading
(too old to reply)
andrewq2
2008-04-09 12:30:56 UTC
Permalink
Cant get dev-pascal to read from a text file contaning a key(key.txt)
code:
uses crt;
label
start;
label
stop;
var
y : byte;
x : byte;
F1 : text;
FN1 : string;
begin
FN1 := 'key.txt';

assign( F1, FN1 );
reset( F1 );

while not EOLN( F1 ) do
begin
readln( F1 );
val(fn1,y);
if y=15712774 then goto start
else;
begin
writeln('Invalid Licence #',y,'');
writeln('now exting');
goto stop;
end;

close( F1 );
start:
repeat
{code}
until x=47;
stop:
end;
end.
Maurice Lombardi
2008-04-09 15:54:06 UTC
Permalink
Post by andrewq2
Cant get dev-pascal to read from a text file contaning a key(key.txt)
some suggestions below
Post by andrewq2
uses crt;
label
start;
label
stop;
var
y : byte;
^ 15712774 is too large for a byte, and even
for a 16 bit integer;
use integer (gpc or delphi: 32 bits) or longint (BP)
Post by andrewq2
x : byte;
F1 : text;
FN1 : string;
begin
FN1 := 'key.txt';
assign( F1, FN1 );
reset( F1 );
while not EOLN( F1 ) do
begin
readln( F1 );
( F1, FN1) ???
Post by andrewq2
val(fn1,y);
if y=15712774 then goto start
else;
^ do you really want a ; there.
The following begin end block is _not_ the else clause.
Anyway it makes no change in this case !!!
Post by andrewq2
begin
writeln('Invalid Licence #',y,'');
writeln('now exting');
goto stop;
end;
close( F1 );
repeat
{code}
until x=47;
end;
^ position of this end implies that you can have in F1
several lines with different Licence # and treat all
with a warning if the leadings are not 15712774.
Is that you want ?
Post by andrewq2
end.
--
Maurice Lombardi
Laboratoire de Spectrometrie Physique,
Universite Joseph Fourier de Grenoble, BP87
38402 Saint Martin d'Heres Cedex FRANCE
Tel: 33 (0)4 76 51 47 51
Fax: 33 (0)4 76 63 54 95
mailto:***@ujf-grenoble.fr
Loading...