• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

displaying a whole text on the screen

Hi everybody,

i need some help about screen managing things
for example i wrote a program which read a whole text from a txt-file and it should write it on the screen
the text is stored in an array of string, 400 lines
but if i do something like that the user can't read the line from 1 to 360

FOR i:=1 To 400 Do
 WriteLn(WholeText[i]);

the main purpose of the program is that the user could read the WHOLE text and not just the 40 last lines,
i would like to activate something like the "Page-Up and Page-Down" keys
so that the user could go to the top and browse around

can someone help me out if that ???

here is the code i now have;
PROGRAM Test; Uses DOS;
CONST
 i:Integer=0;

VAR
 WholeText:Array[1..400] Of String[100];
 F:Text;
 sr:SearchRec;

BEGIN
 FindFirst('readme.*', AnyFile, sr);
 While DosError = 0 Do
 Begin
  Assign(F,sr.Name);
  Reset(F);

   While Not (Eof(F)) DO
   Begin
    i:=i+1;
    ReadLn(F, WholeText[i]);
   End;

  Close(F);
  FindNext(sr);
 End;
 ReadLn;
END.

it is very primitive, it is just to illustrate the problem i have
0
Elvis1
Asked:
Elvis1
  • 2
2 Solutions
 
Jase-CoderCommented:
consoles have about 24 rows and 80 collumns so, to view the whole file your going to have to display 23 lines then you could tell the user to press a key, then clear the screeen then display another 23 lines. so simple peusdo

Display 23 lines
prompt user for key press
clear then screen
Display 23 lines

to display 23 lines you could read 80 chars from the file then display that on screen so

while (not eof) do
begin
  for a := 1 to 23 do
  begin
    for i := 1 to 80 do
    begin
       read(F, Str[i]);
    end;
    writeln(str);
  end;
  writeln('Press a key');
  readln;
end;

I have had chance to compile this so you might find some errors
 
0
 
mlmccCommented:
Is this a homework assignment or something you are doing on your own?  Sounds like an assignment we did to start writing a text editor.

Basic idea

Read the file as you are doing
---
   lines := 1;
   While Not (Eof(F)) DO
   Begin
   lines := lines +1;
    ReadLn(F, WholeText[lines]);
   End;
---
Display 1 screen of text
   start := 1;
  Repeat
   For i = start to start+22 do
     Writeln (WholeText[i]);
   Display keycodes
   When a key is hit - respond
   Pgup  start := start;
   Pgdn  start := start + 22;
   Quit
  until quit

Needs a fair amount of work but bit gives you the ggeneral idea.

mlmcc
   
0
 
Elvis1Author Commented:
it's something i'm doing on my own, it is in fact to write a basic text editor, i'm folowing a tutorial,

i look it up, consoles have 80 columns and 25 rows
so for a nice layout i should take the first line for my heading and menu and so on and the last line is to ask the user for page-up or page-down ???

Elvis
0
 
mlmccCommented:
Glad I could help

mlmcc
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now