BBS: Inland Empire Archive
Date: 01-31-93 (07:59)             Number: 356
From: TOM HAMMOND                  Refer#: NONE
  To: DENIS DUBUC                   Recvd: NO  
Subj: Help                           Conf: (2) Quik_Bas
DD>I would like to know how to the Command for viewing a text file that
   is more then 25 line long by having a thing like press a key to
   continue without having the file scrolling down to the END.The only
   thing that I've been able to do so far is using the | MORE Command,
   but there must be another way to control the text, I checked the 3
   Books that I have but I haven't find anything. Could someone please
   help me?

This may be more than you wanted, but it works GREAT... courtesy of Matt
Hart... who used to frequent this Echo but who had been hiding
recently... too bad, he was a REAL help to us newbies...

NOTE that two (2) lines in the code to follow have been broken (wrapped)
to the next line because they were too long to fit into the editor line
length as-is.  Each broken line has a single underline '_' at its end to
indicate that the text from the NEXT line must be brought UP to THAT
line when you edit the code.  Be sure to REMOVE the underline after
merging the two lines back into one.

BTW, the KeyProcess subroutine is EXCELLENT for other uses.. I keep a
copy of just that code and use it all the time.  It's a great snippet to
learn from.

Good luck - Tom Hammond

' VIEWFILE.BAS  by Matt Hart
' View any size text file without any temporary files.
' Keeps the SEEK position of each line in a long integer array -
' which does limit this to 16,384 lines of text (and makes this
' program easy, small, and fast.)  Key controls are <UpArrow>, <DnArrow>,
' <LtArrow>, <RtArrow>, <PgUp>, <PgDn>, <End>, <Home> and <Esc>.


    CONST false = 0
    CONST true = NOT false

    LINE INPUT "File Name: "; File$

    Escape = false

    OPEN "I", 1, File$
    REDIM Seeks&(1 TO 16384)        ' Max number of lines if 16384
    CurSeek& = 1
    NumLines = 0
        LINE INPUT #1, Text$
        NumLines = NumLines + 1
        Seeks&(NumLines) = CurSeek&          ' Save starting position
        CurSeek& = CurSeek& + LEN(Text$) + 2 ' Next position - 2 is
    LOOP                                     ' for C/R & LF

    CurCol = 1                               ' Current Column
    SeekEl = 1                               ' Current line
    Escape = false

        GOSUB LoadAndDisplay
        GOSUB KeyProcess
    LOOP UNTIL Escape

    CLOSE 1

    SEEK #1, Seeks&(SeekEl)
    FOR i = 1 TO 24
        IF NOT EOF(1) THEN LINE INPUT #1, Text$ ELSE Text$ = ""
        Strg$ = SPACE$(80)
        IF LEN(Text$) < CurCol THEN Text$ = Text$_
 + SPACE$(CurCol - LEN(Text$))
        LSET Strg$ = MID$(Text$, CurCol)
        LOCATE i, 1, 0: PRINT Strg$;
    NEXT i

    A$ = INKEY$: IF A$ = "" THEN GOTO KeyProcess
        CASE CHR$(27): Escape = true        ' <Esc>
        CASE CHR$(0) + CHR$(72)             ' <UpArrow>
            SeekEl = SeekEl - 1
            IF SeekEl < 1 THEN SeekEl = 1: GOTO KeyProcess
        CASE CHR$(0) + CHR$(80)             ' <DnArrow>
            SeekEl = SeekEl + 1
            IF SeekEl + 23 > NumLines THEN SeekEl = SeekEl - 1:_
 GOTO KeyProcess

    CASE CHR$(0) + CHR$(77)             ' <RtArrow>
            CurCol = CurCol + 1
        CASE CHR$(0) + CHR$(75)             ' <LtArrow>
            CurCol = CurCol - 1
            IF CurCol < 1 THEN CurCol = 1: GOTO KeyProcess
        CASE CHR$(0) + CHR$(73)             ' <PgUp>
            SeekEl = SeekEl - 24
            IF SeekEl < 1 THEN SeekEl = 1
        CASE CHR$(0) + CHR$(81)             ' <PgDn>
            SeekEl = SeekEl + 24
            IF SeekEl > NumLines THEN
                SeekEl = NumLines - 23: GOTO KeyProcess
            END IF
        CASE CHR$(0) + CHR$(71)             ' <Home>
            SeekEl = 1
        CASE CHR$(0) + CHR$(79)             ' <End>
            SeekEl = NumLines - 23
            IF SeekEl < 1 THEN SeekEl = 1: GOTO KeyProcess
        CASE ELSE
            GOTO KeyProcess
 * Origin: Night Shift BBS (314)635-7588 HST 14.4 (1:289/15)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET