need help again - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

need help again

joelem18joelem18 Posts: 31Member
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

Comments

  • Phat NatPhat Nat Posts: 757Member
    : 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.

    [code]
    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.
    [/code]

    This is the basic idea. This doesn't check to see if [b]Selection[/b] is within 1-3 and this writing method makes the code a little bit long, but it should get you started.

    Phat Nat

  • joelem18joelem18 Posts: 31Member
    I tried your program but it doesn't seem to work well. I tried fixing it up but i didn't manage
  • joelem18joelem18 Posts: 31Member
    : I tried your program but it doesn't seem to work well. I tried fixing it up but i didn't manage
    :
    Sorry my fault, it works fine. I wanted to ask, let's sa i have an index file and i list all the student's according to their name and surname. How can i use the left and right keys and home and end keys in addition to the up and down keys?

  • Phat NatPhat Nat Posts: 757Member
    : : I tried your program but it doesn't seem to work well. I tried fixing it up but i didn't manage
    : :
    : Sorry my fault, it works fine. I wanted to ask, let's sa i have an index file and i list all the student's according to their name and surname. How can i use the left and right keys and home and end keys in addition to the up and down keys?

    Note the addition to the following code:
    [code]
    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);
    [b]ELSE WriteLn(Ord(Key));[/b]
    End;
    End;
    Until Key = #27;
    End.
    [/code]

    If the key you press isn't listed (up & down in this case) it will display the ordinal value of that key (75=LEFT, 77=RIGHT). I don't have Home/End/PageUp/PageDown/etc memorized, but it will tell you their values when you press the key.

    Phat Nat
Sign In or Register to comment.