home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / QBAS / QBNWS301.ZIP / VIEWFILE.BAS < prev    next >
BASIC Source File  |  1992-03-19  |  3KB  |  86 lines

  1. ' VIEWFILE.BAS  by Matt Hart
  2. ' View any size text file without any temporary files.
  3. ' Keeps the SEEK position of each line in a long integer array -
  4. ' which does limit this to 16,384 lines of text (and makes this
  5. ' program easy, small, and fast.)  Key controls are up, down,
  6. ' left, right, page up, page down, end, home, and escape.
  7. '
  8.     '$DYNAMIC
  9.     DEFINT A-Z
  10. '
  11.     CONST false = 0
  12.     CONST true = NOT false
  13.     CLS
  14.     LINE INPUT "File Name: "; File$
  15. '   File$ = "VIEW.BAS"
  16. '   File$ = "c:\binkley\nodelist\nodelist.235"
  17.     Escape = false
  18. '
  19.     OPEN "I", 1, File$
  20.     REDIM Seeks&(1 TO 16384)        ' Max number of lines if 16384
  21.     CurSeek& = 1
  22.     NumLines = 0
  23.     DO UNTIL EOF(1)
  24.         LINE INPUT #1, Text$
  25.         NumLines = NumLines + 1
  26.         Seeks&(NumLines) = CurSeek&          ' Save starting position
  27.         CurSeek& = CurSeek& + LEN(Text$) + 2 ' Next position - 2 is
  28.     LOOP                                     ' for C/R & LF
  29. '
  30.     CurCol = 1                               ' Current Column
  31.     SeekEl = 1                               ' Current line
  32.     Escape = false
  33.  
  34.     DO
  35.        GOSUB LoadAndDisplay
  36.        GOSUB KeyProcess
  37.     LOOP UNTIL Escape
  38.  
  39.     CLOSE 1
  40.     END
  41.  
  42. LoadAndDisplay:
  43.     SEEK #1, Seeks&(SeekEl)
  44.     FOR i = 1 TO 24
  45.         IF NOT EOF(1) THEN LINE INPUT #1, Text$ ELSE Text$ = ""
  46.         Strg$ = SPACE$(80)
  47.         IF LEN(Text$) < CurCol THEN Text$ = Text$ + SPACE$(CurCol - LEN(Text$))
  48.          LSET Strg$ = MID$(Text$, CurCol)
  49.         LOCATE i, 1, 0: PRINT Strg$;
  50.     NEXT i
  51. RETURN
  52.  
  53. KeyProcess:
  54.     A$ = INKEY$: IF A$ = "" THEN GOTO KeyProcess
  55.     SELECT CASE A$
  56.         CASE CHR$(27): Escape = true        ' ESC
  57.         CASE CHR$(0) + CHR$(72)             ' Up Arrow
  58.             SeekEl = SeekEl - 1
  59.             IF SeekEl < 1 THEN SeekEl = 1: GOTO KeyProcess
  60.         CASE CHR$(0) + CHR$(80)             ' Dn Arrow
  61.             SeekEl = SeekEl + 1
  62.             IF SeekEl + 23 > NumLines THEN SeekEl = SeekEl - 1: GOTO KeyProcess
  63.          CASE CHR$(0) + CHR$(77)             ' Right Arrow
  64.             CurCol = CurCol + 1
  65.         CASE CHR$(0) + CHR$(75)             ' Left Arrow
  66.             CurCol = CurCol - 1
  67.             IF CurCol < 1 THEN CurCol = 1: GOTO KeyProcess
  68.         CASE CHR$(0) + CHR$(73)             ' Page Up
  69.             SeekEl = SeekEl - 24
  70.             IF SeekEl < 1 THEN SeekEl = 1
  71.         CASE CHR$(0) + CHR$(81)             ' Page Dn
  72.             SeekEl = SeekEl + 24
  73.             IF SeekEl > NumLines THEN
  74.                 SeekEl = NumLines - 23: GOTO KeyProcess
  75.             END IF
  76.         CASE CHR$(0) + CHR$(71)                       ' Home
  77.             SeekEl = 1
  78.         CASE CHR$(0) + CHR$(79)                       ' End
  79.             SeekEl = NumLines - 23
  80.             IF SeekEl < 1 THEN SeekEl = 1: GOTO KeyProcess
  81.         CASE ELSE
  82.             GOTO KeyProcess
  83.     END SELECT
  84. RETURN
  85.  
  86.