home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / basic / bmag / fileview.bas < prev    next >
Encoding:
BASIC Source File  |  1994-04-26  |  2.9 KB  |  89 lines

  1. '─ Area: F-QUICKBASIC ─────────────────────────────────────────────────────────
  2. '  Msg#: 352                                          Date: 25 Apr 94  16:53:09
  3. '  From: Bob Perkins                                  Read: Yes    Replied: No 
  4. '    To: Allan Fields                                 Mark:                     
  5. '  Subj: Re: File viewing
  6. '──────────────────────────────────────────────────────────────────────────────
  7. '  I got a bit carried away here and created a little file lister.  This will
  8. 'work with files that are small enough to be loaded into memory.  On my system
  9. 'with 614k available DOS memory this will load over 4000 lines.  You must start
  10. 'QB with "/ah" for this to work.  Also notice that I used 128 bytes as the
  11. 'length of the string.  This gives me more memory to work with than if I'd used
  12. '80 bytes. 
  13. ' To use as much available memory as possible use a power of 2 as the length of
  14. 'your string.  (1,2,4,8,16,32,64,128,etc)
  15. '  Another approach you might consider for reading a text file is to just load a
  16. 'few pages at a time and read ahead/behind as necessary.
  17.  
  18.  '
  19.  'Start QB with "/ah" for huge arrays
  20.  '
  21.  maxmem& = FRE(-1) - 65535
  22.  maxlines% = CINT(maxmem& \ 128)
  23.  '$DYNAMIC
  24.  REDIM array(1 TO maxlines%) AS STRING * 128
  25.  f% = FREEFILE
  26.  OPEN COMMAND$ FOR INPUT AS #f%   'might want to add error-checking
  27.  count% = 0
  28.  DO WHILE NOT EOF(1)
  29.   count% = count% + 1
  30.   IF count% > maxlines% THEN
  31.     PRINT "Cannot load entire file!  "; maxlines%; " lines read."
  32.     PRINT "Press Any Key to Continue...";
  33.     DO: LOOP UNTIL LEN(INKEY$)
  34.     count% = maxlines%: EXIT DO
  35.   END IF
  36.   LINE INPUT #1, array(count%)
  37.  LOOP
  38.  CLOSE #f%
  39.  COLOR 7, 1: CLS
  40.  LOCATE 25, 1: COLOR 0, 7: PRINT SPACE$(80);
  41.  LOCATE , 14
  42.  PRINT "File Viewer"; SPACE$(15); CHR$(179);
  43.  PRINT SPACE$(12); "Press ESC to exit";
  44.  COLOR 7, 1
  45.  top% = 1
  46.  DO
  47.   FOR x% = top% TO top% + 23
  48.     LOCATE x% - top% + 1, 1: PRINT LEFT$(array(x%), 80);
  49.   NEXT x%
  50.   DO
  51.     a$ = INKEY$
  52.     IF LEN(a$) THEN
  53.       IF LEN(a$) = 2 THEN
  54.         test% = -ASC(RIGHT$(a$, 1))
  55.       ELSE
  56.         test% = ASC(a$)
  57.       END IF
  58.       SELECT CASE test%
  59.         CASE 27: CLS : END
  60.         CASE -79                                 'END
  61.           top% = count% - 23
  62.           EXIT DO
  63.         CASE -71                                 'HOME
  64.           top% = 1
  65.           EXIT DO
  66.         CASE -73, -72                            'PgUp/Up-Arrow
  67.           IF test% = -73 THEN
  68.             top% = top% - 24
  69.           ELSE
  70.             top% = top% - 1
  71.           END IF
  72.           IF top% < 1 THEN top% = 1
  73.           EXIT DO
  74.         CASE -81, -80                            'PgDn/Dn-Arrow
  75.           IF test% = -81 THEN
  76.             top% = top% + 24
  77.           ELSE
  78.             top% = top% + 1
  79.           END IF
  80.           IF top% + 23 > count% THEN top% = count% - 23
  81.           EXIT DO
  82.       END SELECT
  83.     END IF
  84.   LOOP
  85.  LOOP
  86.  COLOR 7, 0: CLS
  87.  
  88.  
  89.