help

 BBS: Inland Empire Archive
Date: 01-31-93 (21:28)             Number: 333
From: MATT HART                    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

'
' 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 up, down,
' left, right, page up, page down, end, home, and escape.
'
    '$DYNAMIC
    DEFINT A-Z
'
    CONST False = 0
    CONST True  = NOT False
'
    File$="VIEWFILE.BAS"
    Escape=false
'
    OPEN "I",1,File$
    REDIM Seeks&(1 to 16384)        ' Max number of lines is 16384
    CurSeek& = 1
    NumLines = 0
    DO UNTIL EOF(1)
        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
DO
    gosub LoadAndDisplay
    gosub KeyProcess
LOOP UNTIL Escape
    CLOSE 1
    END
LoadAndDisplay:
    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
RETURN
KeyProcess:
    A$=INKEY$ : IF A$="" THEN GOTO KeyProcess
    SELECT CASE A$
        CASE CHR$(27) : Escape = true       ' ESC
        CASE CHR$(0)+CHR$(72)               ' Up Arrow
            SeekEl=SeekEl-1
            if SeekEl<1 then SeekEl=1:GOTO KeyProcess
        CASE CHR$(0)+CHR$(80)               ' Dn Arrow
            SeekEl=SeekEl+1
            if SeekEl+23>NumLines then SeekEl=SeekEl-1:GOTO KeyProcess
        CASE CHR$(0)+CHR$(77)               ' Right Arrow
            CurCol=CurCol+1
        CASE CHR$(0)+CHR$(75)               ' Left Arrow
            CurCol=CurCol-1
            if CurCol<1 then CurCol=1:GOTO KeyProcess
        CASE CHR$(0)+CHR$(73)               ' Page Up
            SeekEl=SeekEl-24
            if SeekEl<1 then SeekEl=1
        CASE CHR$(0)+CHR$(81)               ' Page Dn
            SeekEl=SeekEl+24
            if SeekEl-23<NumLines then
                SeekEl=NumLines-23
                if SeekEl<1 then SeekEl=1:GOTO KeyProcess
            endif
        CASE CHR$(71)                       ' Home
            SeekEl = 1
        CASE CHR$(79)                       ' End
            SeekEl=NumLines-23
            if SeekEl<1 then SeekEl=1:GOTO KeyProcess
        CASE ELSE
            GOTO KeyProcess
    END SELECT
RETURN
---
 * Origin: Midnight Micro!  V.32/REL  (918)451-3306 (1:170/600)
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