Antagonist
Programmer
I'm writing a program at the moment in TP 7 and have come across a problem. The program is a translation quiz, where it asks for translations from one language to another.
At the moment i get the information for the questions from one file (at random) and the answers from another, which are then written to temporary variables.
I'm opening and closing the same 2 files over and over, as they are part of a repeat loop. But i find that when it tries to open the files for 15th file i get the Error 4 message: Too many open files.
So basically, in order to prevent writing more code, and make the program more difficult to add words to later, i'm wondering if there is a way to constantly read from a file without crashing the program. I mean i'd be probably looking to open these files up to 200 times per running.
Each time i read from the files, i read a random line, and lets say there could be 500 lines (words) in the file (at the moment there are 10), i don't want to declare 1000 constants.
I'm new it this, there may be an easy way around this, if so i'm all ears :>
Åñt
{ file1,file2,qstring,astring,answer:string }
Procedure DutchVocab;
Begin
ClrScr;
file1:= 'C:\TK\Dutch.txt';
file2:= 'C:\TK\English1.txt';
Writeln;
Write ('How many words to practice? ');
readln (Qlast);
Q:=0;
score:=0;
ClrScr;
Repeat
ClrScr;
Randomize;
RanVal:=Random(10);
Assign (input,file1);
reset (input);
line:=0;
Repeat
Readln (Qstring);
line:=line+1;
until line = RanVal;
close (input);
assign (input,'con');
reset(input);
Assign (input,file2);
reset (input);
line:=0;
Repeat
Readln (Astring);
line:=line+1
until line = RanVal;
close (input);
assign (input,'con');
reset(input);
Q:=Q+1;
Writeln ('Translate the following into English');
Writeln;Writeln;
Writeln (Qstring);
Writeln;
Write ('=> ');
readln (Answer);
If Answer = Astring then begin
Writeln;
Writeln ('Correct!');
score:=score+1;
delay (3000);
end
else begin
Writeln;
Writeln ('Incorrect, the answer was ',Astring,'.');
delay(3000);
end;
Until Q=Qlast;
end;
At the moment i get the information for the questions from one file (at random) and the answers from another, which are then written to temporary variables.
I'm opening and closing the same 2 files over and over, as they are part of a repeat loop. But i find that when it tries to open the files for 15th file i get the Error 4 message: Too many open files.
So basically, in order to prevent writing more code, and make the program more difficult to add words to later, i'm wondering if there is a way to constantly read from a file without crashing the program. I mean i'd be probably looking to open these files up to 200 times per running.
Each time i read from the files, i read a random line, and lets say there could be 500 lines (words) in the file (at the moment there are 10), i don't want to declare 1000 constants.
I'm new it this, there may be an easy way around this, if so i'm all ears :>
Åñt
{ file1,file2,qstring,astring,answer:string }
Procedure DutchVocab;
Begin
ClrScr;
file1:= 'C:\TK\Dutch.txt';
file2:= 'C:\TK\English1.txt';
Writeln;
Write ('How many words to practice? ');
readln (Qlast);
Q:=0;
score:=0;
ClrScr;
Repeat
ClrScr;
Randomize;
RanVal:=Random(10);
Assign (input,file1);
reset (input);
line:=0;
Repeat
Readln (Qstring);
line:=line+1;
until line = RanVal;
close (input);
assign (input,'con');
reset(input);
Assign (input,file2);
reset (input);
line:=0;
Repeat
Readln (Astring);
line:=line+1
until line = RanVal;
close (input);
assign (input,'con');
reset(input);
Q:=Q+1;
Writeln ('Translate the following into English');
Writeln;Writeln;
Writeln (Qstring);
Writeln;
Write ('=> ');
readln (Answer);
If Answer = Astring then begin
Writeln;
Writeln ('Correct!');
score:=score+1;
delay (3000);
end
else begin
Writeln;
Writeln ('Incorrect, the answer was ',Astring,'.');
delay(3000);
end;
Until Q=Qlast;
end;