: I thank all those that helped me with the file problem. But it seems problems won't just stop turning up. I don't know how to use arrow keys to move from one field to another. The thing is that i am asked to move through the fields to fix the data in the records if necessary but i have no idea of how the code to move between fields is. All i need is to move through the following fields:
: Student name
: Student surname
: Subjects
:
: (I only need to use up and down arrow keys)
:
: Here's my code
:
: Procedure Amend;
: var
: i, ts : integer;
: choice : char;
:
: begin
: clrscr;
: ts := 1;
: assign(mainfile, 'C:\main.dat');
: reset(mainfile);
: for i := 1 to filesize(mainfile) do
: begin
: ts := 1;
: reset(mainfile);
: seek(mainfile, filesize(mainfile) - i);
: read(mainfile, onestud);
: gotoxy(20, 12);
: Writeln('Student Name : ', onestud.name);
: gotoxy(20, 13);
: Writeln('Student Surname : ', onestud.surname);
: gotoxy(20, 14);
: Write('Subjects : ');
: while onestud.subs <> [] do
: begin
: if ts in onestud.subs then
: begin
: write(subject_array[ts], ' ');
: onestud.subs := onestud.subs - [ts];
: end;
: inc(ts);
: end;
: choice := Readkey;
: case choice of
: #0: Begin
: Case choice Of
: #72: begin
: gotoxy(20, 28);
: writeln(newname);
: end;
:
: #80:
: end;
: end;
: end;
:
: readln;
: close(mainfile);
: end;
: end;
:
: (I tried doing something but i didn't manage)
: Thanks
To use the arrow keys, you need to do a dual key read. If the first key = char(0) then you need to read the keystroke again. The second character will be the value that you want to compare. For the arrows, the characters that define them are UP=char(72) and DOWN=char(80).
As for moving through fields, the easiest way is to just keep re-writing the data onto the screen and when the selected line is being written to the screen, change the background to a different color.
USES Crt, Dos;
VAR
Selection : ShortInt;
Key : Char;
Begin
Repeat
If Selection = 0 Then TextBackground(1) ELSE TextBackground(0);
WriteLn('Choice #1');
If Selection = 1 Then TextBackground(1) ELSE TextBackground(0);
WriteLn('Choice #2');
If Selection = 2 Then TextBackground(1) ELSE TextBackground(0);
WriteLn('Choice #3');
Key := Readkey;
If Key = #0 Then
Begin
Key := Readkey;
Case Key Of
#72 : Dec(Selection);
#80 : Inc(Selection);
End;
End;
Until Key = #27;
End.
This is the basic idea. This doesn't check to see if
Selection is within 1-3 and this writing method makes the code a little bit long, but it should get you started.
Phat Nat