Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
need help again Posted by joelem18 on 26 Apr 2003 at 9:46 AM
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

Report
Re: need help again Posted by Phat Nat on 26 Apr 2003 at 6:20 PM
: 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

Report
Re: need help again Posted by joelem18 on 27 Apr 2003 at 4:14 AM
I tried your program but it doesn't seem to work well. I tried fixing it up but i didn't manage
Report
Re: need help again Posted by joelem18 on 27 Apr 2003 at 4:22 AM
: 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?

Report
Re: need help again Posted by Phat Nat on 28 Apr 2003 at 7:33 AM
: : 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:
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);
                 ELSE WriteLn(Ord(Key));
                End;
           End;
     Until Key = #27;
End.


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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.