Scroll Box

Hi! Is there any way for me to create a scroll box (of text) with a set of not-too-complicated procedure/function?
Like only the text inside the box scrolls and stuff outside it stays fixed.
I am a high school student and am doing a school coursework on a phone directory, complicated programs are kinda 'out of league'. Thanks!

Comments

  • : Hi! Is there any way for me to create a scroll box (of text) with a
    : set of not-too-complicated procedure/function?
    : Like only the text inside the box scrolls and stuff outside it stays
    : fixed.

    Here's an example showing the most simplistic way, although it can only go one way:[code][color=Blue]uses crt;
    var i,l:word;

    begin
    for i:=1 to 4000 do write(#178); { fill screen with something }
    gotoxy(9,8);
    write(' Scroll box ');
    window(10,10,40,20); { define a window for the scroll box }
    clrscr; { clear window }
    while not(keypressed) do begin
    l:=2+random(8); { create a random word }
    for i:=1 to l do begin write(chr(65+random(26)));delay(5);end;
    write(' ');
    delay(25); { slight delay }
    end;
    readkey;
    window(1,1,80,25); { restore active area to screen size }
    end.[/color][/code]

  • Thank you.It is really helpful.
    How about if I want to load a file in a scrollbox so it can be, well, scrolled.
    I know how to load text files. And I know how to scroll on a full page. But I use gotoxy, so it doesn't quite work in a box, or at least not with the little knowledge I have. Is there a way to achieve this?
    Thanks.
  • : How about if I want to load a file in a scrollbox so it can be,
    : well, scrolled.
    : I know how to load text files. And I know how to scroll on a full
    : page. But I use gotoxy, so it doesn't quite work in a box, or at
    : least not with the little knowledge I have. Is there a way to
    : achieve this?

    Here's a text viewer with some limitations to avoid being too complex ( 809 lines of text maximum, 80 char long lines at most, no wrapping, will clip at scroll box boundary, doesn't scroll lines by lines only pages ), but it's setup allows for easy expansion:[code][color=Blue]{ Compiler: BP/TP 7 }

    {$A+,B-,D-,E-,F-,G+,I-,L-,N+,O-,P-,Q-,R-,S-,T-,V-,X+}
    {$M 16384,0,655360}
    uses crt;

    const wpx:byte=5; { view window position x coord }
    wpy:byte=5; { view window position y coord }
    wsx:byte=60;{ view window x size }
    wsy:byte=15;{ view window y size }

    var fn:string; { file name }
    f:text;

    type buffer=array[1..809] of string[80]; { 65529 bytes to fit a 64k segment }

    procedure run;
    var buf:^buffer; { pointer to buffer }
    ext:boolean;
    curl,maxl:word; { current line, max. line }
    ch:char;

    procedure display;
    var s:string;
    sl:byte absolute s; { sl:=lenght(s); <-- auto updating }
    i:word;
    begin
    window(wpx,wpy,pred(wpx+wsx),pred(wpy+wsy));{ define display window }
    clrscr; { clear window }
    window(1,1,80,25); { reset window to screen size }
    gotoxy(wpx,wpy); { move cursor to start coords.}
    i:=curl;
    while ((wherey<wsy+wpy) and (i<=maxl)) do begin { check boundaries }
    s:=buf^[i];
    if sl>wsx then begin { clip line if longer then window x size }
    sl:=pred(wsx);write(s);
    textcolor(14);write('>');textcolor(7);end
    else write(s); { display line }
    gotoxy(wpx,wherey+1); { move cursor to next line }
    inc(i); { increment buffer pointer }
    end;
    gotoxy(80,25); { move cursor away from the display window }
    end;

    begin
    new(buf); { reserve memory for buffer }
    maxl:=0;
    while (not(eof(f)) and (maxl<809)) do begin { check for end of file and }
    inc(maxl); { buffer fill level }
    readln(f,buf^[maxl]); { read a line into buffer }
    end;
    ext:=false; { init exit control variable }
    clrscr;
    for curl:=1 to 2000 do write(#178); { fill screen w/ graph. chars }
    textbackground(1);textcolor(15);
    gotoxy(1,1); write(' Viewing: ');
    gotoxy(12,1);write(fn);
    gotoxy(32,1);write(maxl,' lines ');
    gotoxy(1,25);write(' Press: PgUp/PgDn/Home/End to navigate Esc to Exit ');
    textbackground(0);textcolor(7);
    curl:=1;
    display;
    repeat { main loop }
    if keypressed then begin { check for user input }
    ch:=readkey; { get scancode for depressed key }
    case ch of
    #27:{Esc}ext:=true;
    #0 :{Extended code} begin
    ch:=readkey; { second scan to get the extended keyboard code }
    case ch of
    #71:{Home}begin curl:=1;display;end;
    #81:{PgDn}if curl<=maxl-wsy then begin inc(curl,wsy);display;end
    else write(#7);
    #73:{PgUp}if curl=1 then write(#7) else begin
    if curl>wsy then dec(curl,wsy) else curl:=1;display;end;
    #79:{ End}begin
    if maxl-wsy>0 then curl:=succ(maxl-wsy) else curl:=1;
    display;
    end;
    end;
    end;
    end;
    end;
    until ext; { end main loop }
    clrscr;
    dispose(buf); { free memory previously reserved }
    end;


    {#### Main ##################################################################}
    begin
    if memavail>70000 then begin { check for memory availability }
    write('File to view: ');readln(fn); { get user to input file to open }
    assign(f,fn); { }
    reset(f); { open file for read, recsize = 1 }
    if ioresult<>0 then begin { check for input/output errors }
    writeln(fn,' not found ! Exiting.'); { echo user if something is wrong }
    halt; { exit program }
    end; { }
    if not(eof(f)) then run { check if its an empty file }
    else writeln(fn,' is an empty file.'); { file size = 0 }
    close(f); { close file }
    end else writeln('Not enough memory to run application !');
    end.[/color][/code]
  • THANK YOU SO MUCH!!!
Sign In or Register to comment.

Howdy, Stranger!

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

Categories