SUB TrueView (FileName$, ULRow%, ULCol%, LRRow%, LRCol%, FGColr%, BGColr%, TBColrFG%, TBColrBG%, TBNumColrFG%, TBNumColrBG%, EOFColrFG%, EOFColrBG%) ' +----------------------------------------------------------------------+ ' | | ' | ð T R U E V I E W F I L E B R O W S E R ð | ' | - - - - - - - - - - - - - - - - - - - | ' | (This SUB can be very easily made into a stand alone program.) | ' +----------------------------------------------------------------------+ ' +----------------------------------------------------------------------+ ' | TrueView.Bas written by Don Smith on 05/20/2002. Written for | ' | QuickBASIC 4.5. No special libraries are needed. Released to | ' | the public domain. Programmers need not give my name. They can | ' | even change the name of the program. | ' | | ' | If this is to be made into a stand alone program, programmers | ' | will probably want to include an error screen using: | ' | ON ERROR GOTO errorhandler | ' |----------------------------------------------------------------------| ' | Information about the author: | ' | ---------------------------- | ' | Hello, my name is Don Smith and I am a retired Math/History/Spanish | ' | teacher currently residing in Orange County, California. | ' | | ' | My email is: smithdonb@earthlink.net | ' |----------------------------------------------------------------------| ' | TrueView is an ASCII text browser. TrueView is so written as to | ' | avoid having to rely on Dimensioning or Redimensioning. It | ' | continuously keeps track of where the top line is, and it | ' | continuously opens and closes the COMMAND$ file. There is never | ' | a need to worry about how much memory is needed. | ' |----------------------------------------------------------------------| ' | If is pressed, the screen is saved and moved up | ' | or down and only one line is brought in to complete the screen. | ' | and work also to move text up or down. If | ' | is pressed then the next screen page is presented. | ' |----------------------------------------------------------------------| ' | Trueview probably shouldn't be used for huge files longer than | ' | 10000 lines. Beyond 10000 lines, it slows down a tad. I have a | ' | Pentium 4 2.65 CPU Ghz Gateway computer running under WindowsXP, | ' | and Trueview really did not lag in reading a 10,000 line file. I | ' | tried it out, however, on my old Pentium-S 166 Mhz computer, and | ' | it did lag a tiny bit, but not badly. ' |----------------------------------------------------------------------| ' | Compiling: | ' | | ' | BC: TrueView /e 'use /e for errors | ' | | ' | LINK: TrueView /noe | ' | LIB : BCom45 | ' | | ' +----------------------------------------------------------------------+ ' +---------------+------------------------------------------------------+ ' | FileName$ | The ASCII text file to view. As a stand alone | ' | | program, FileName$ will be a give as a command | ' | | line parameter and will look like this at the top | ' | | of the program: FileName$ = COMMAND$ | ' |---------------+------------------------------------------------------| ' | ULRow% | Upper left row to place text. | ' |---------------+------------------------------------------------------| ' | ULCol% | Upper left column to place text. | ' |---------------+------------------------------------------------------| ' | LRRow% | Lower right row to place text. | ' |---------------+------------------------------------------------------| ' | LRCol% | Lower right column to place text. | ' |---------------+------------------------------------------------------| ' | FGColr% | Foreground color of text (0-15). | ' |---------------+------------------------------------------------------| ' | BGColr% | Back ground color of text (0-7). | ' |---------------+------------------------------------------------------| ' | TBColrFG% | Foreground color of top/bottom strips (0-15). | ' |---------------+------------------------------------------------------| ' | TBColrBG% | Background color of the top/bottom strips (0-7). | ' |---------------+------------------------------------------------------| ' | TBNumColrFG% | Foreground color of top line numbering (0-15). | ' |---------------+------------------------------------------------------| ' | TBNumColrBG% | Background color of bottom line numbering (0-7). | ' |---------------+------------------------------------------------------| ' | EOFColrFG% | Foreground color of "End Of File" message (0-15). | ' |---------------+------------------------------------------------------| ' | EOFColrBG% | Background color of "End Of File" message (0-7). | ' +---------------+------------------------------------------------------+ FileName$ = RTRIM$(LTRIM$(FileName$)) SR.UL.Row% = ULRow% 'Upper left row to save/restore screen. SR.UL.Col% = ULCol% 'Upper left column to save/restore screen SR.LR.Row% = LRRow% 'Lower right row to save/restore screen. SR.LR.Col% = LRCol% 'Lower right column to save/restore screen. ' Temp.UL.Row% = SR.UL.Row% + 1 Temp.LR.Row% = SR.LR.Row% - 1 DownUp& = 1 ' 'next 9 lines set up the beginning screen and then closes OpeningScreen% = LRRow% - ULRow% + 1 OPEN FileName$ FOR INPUT AS #1 COLOR FGColr%, BGColr%: CLS FOR BringIt% = 1 TO OpeningScreen% IF EOF(1) THEN EXIT FOR LINE INPUT #1, M$ IF RTRIM$(LTRIM$(M$)) = CHR$(12) THEN M$ = SPACE$(80) LOCATE BringIt% + ULRow% - 1, ULCol%, 0, 0, 0 LOCATE , , 0, 0, 0 PRINT M$; CheckLines% = CheckLines% + 1 NEXT IF CheckLines% < 23 THEN EndYes% = 1: EndPg% = 1: EndOfPage% = 1 END IF GOSUB paint.top.bottom CLOSE #1 loopdeloop: DO IF DownUp& <= 0 THEN DownUp& = 1 END IF COLOR TBNumColrFG%, TBNumColrBG% LOCATE ULRow% - 1, 71, 0, 0, 0: PRINT " "; LOCATE ULRow% - 1, 71, 0, 0, 0: PRINT STR$(DownUp&); LOCATE LRRow% + 1, 71, 0, 0, 0: PRINT " "; LOCATE LRRow% + 1, 71, 0, 0, 0: PRINT STR$(DownUp& + (LRRow% - ULRow%)); COLOR FGColr%, BGColr% DO TheKey$ = INKEY$ LOOP UNTIL LEN(TheKey$) > 0 TheKey% = CVI(TheKey$ + CHR$(0)) IF TheKey% = 20480 OR TheKey% = 19712 THEN ' IF Booboo% = 1 OR CheckLines% < 23 THEN GOTO loopdeloop ELSE EndYes% = 0: EndPg% = 0 FileEnd% = 0 END IF DnAr% = 1 UpAr% = 0 IF EndOfFile% <> 1 THEN SR.UL.Row% = Temp.UL.Row% SR.LR.Row% = Temp.LR.Row% + 1 GOSUB save.true.screen CLOSE #1 OPEN FileName$ FOR INPUT AS #1 FOR DnIt& = 1 TO DownUp& + (LRRow% - ULRow% + 1) IF EOF(1) THEN EndOfFile% = 1 EndPg% = 1 CLOSE #1 EXIT FOR END IF LINE INPUT #1, Fox$ IF RTRIM$(LTRIM$(Fox$)) = CHR$(12) THEN Fox$ = SPACE$(80) Fox$ = LEFT$(Fox$, 80) NEXT IF EndOfFile% <> 1 THEN IF NOT EOF(1) THEN LOCATE LRRow%, ULCol%, 0, 0, 0 PRINT SPACE$(LRCol% - ULCol% + 1); LOCATE LRRow%, ULCol%, 0, 0, 0 PRINT Fox$; ELSEIF EOF(1) THEN LOCATE LRRow%, ULCol%, 0, 0, 0 COLOR EOFColrFG%, EOFColrBG% SOUND 150, 2 PRINT STRING$(35, "-") + "End Of File" + STRING$(34, "-"); END IF END IF DownUp& = DownUp& + 1 ELSEIF EndOfFile% = 1 THEN GOTO loopdeloop END IF ELSEIF TheKey% = 20736 THEN ' IF EndPg% = 1 OR EndYes% = 1 OR EndOfPage% = 1 OR CheckLines% < 23 THEN GOTO loopdeloop END IF IF FileEnd% = 0 THEN CLOSE #1 FileEnd% = 1 END IF PgDn& = DownUp& + LRRow% - ULRow% CLOSE #1 OPEN FileName$ FOR INPUT AS #1 FOR PgDn1& = 1 TO PgDn& IF EOF(1) THEN FileEnd% = 1 CLOSE #1 EXIT FOR END IF LINE INPUT #1, M$ IF RTRIM$(LTRIM$(M$)) = CHR$(12) THEN M$ = SPACE$(80) M$ = LEFT$(M$, 80) NEXT DownUp& = DownUp& + (LRRow% - ULRow% + 1) FOR PgDn2% = 1 TO (LRRow% - ULRow% + 1) IF EndPg% = 0 THEN IF EOF(1) THEN FileEnd% = 1 CLOSE #1 GOSUB da.end.james EXIT FOR END IF END IF LINE INPUT #1, M$ IF RTRIM$(LTRIM$(M$)) = CHR$(12) THEN M$ = SPACE$(80) M$ = LEFT$(M$, 80) LOCATE PgDn2% + 1, ULCol%, 0, 0, 0 PRINT SPACE$(LRCol% - ULCol% + 1); LOCATE PgDn2% + 1, ULCol%, 0, 0, 0 PRINT M$; NEXT ELSEIF TheKey% = 18688 THEN ' Booboo% = 0 EndYes% = 0: EndPg% = 0 IF PgDn& > LRRow% - ULRow% + 1 OR DownUp& > (LRRow% - ULRow% + 1) THEN PgUp& = DownUp& - (LRRow% - ULRow% + 1) CLOSE #1 OPEN FileName$ FOR INPUT AS #1 FOR PgUp1& = 1 TO PgUp& - 1 LINE INPUT #1, M$ IF RTRIM$(LTRIM$(M$)) = CHR$(12) THEN M$ = SPACE$(80) M$ = LEFT$(M$, 80) NEXT FOR PgUp2& = 1 TO (LRRow% - ULRow% + 1) LINE INPUT #1, M$ IF RTRIM$(LTRIM$(M$)) = CHR$(12) THEN M$ = SPACE$(80) M$ = LEFT$(M$, 80) LOCATE PgUp2& + 1, ULCol%, 0, 0, 0 PRINT SPACE$(LRCol% - ULCol% + 1); LOCATE PgUp2& + 1, ULCol%, 0, 0, 0 PRINT M$; NEXT DownUp& = DownUp& - (LRRow% - ULRow% + 1) ELSE GOSUB home.james END IF ELSEIF TheKey% = 18432 OR TheKey% = 19200 THEN ' Booboo% = 0 EndYes% = 0: EndPg% = 0 EndOfFile% = 0 EndPg% = 0 FileEnd% = 0 DnAr% = 0 UpAr% = 1 DownUp& = DownUp& - 1 IF DownUp& = 1 THEN GOSUB home.james ELSEIF DownUp& > 1 THEN SR.UL.Row% = Temp.UL.Row% - 1 SR.LR.Row% = Temp.LR.Row% GOSUB save.true.screen CLOSE #1 OPEN FileName$ FOR INPUT AS #1 FOR UpIt& = 1 TO DownUp& LINE INPUT #1, M$ NEXT IF RTRIM$(LTRIM$(M$)) = CHR$(12) THEN M$ = SPACE$(80) M$ = LEFT$(M$, 80) LOCATE ULRow%, ULCol%, 0, 0, 0 PRINT SPACE$(LRCol% - ULCol% + 1); LOCATE ULRow%, ULCol%, 0, 0, 0 PRINT M$; END IF ELSEIF TheKey% = 18176 THEN ' EndYes% = 0: EndPg% = 0: Booboo% = 0 GOSUB home.james ELSEIF TheKey% = 20224 THEN ' EndPg% = 0: Booboo% = 0 IF EndYes% = 0 THEN GOSUB da.end.james END IF ELSEIF TheKey% = 27 THEN CLOSE #1 EXIT SUB END IF LOOP paint.top.bottom: ' +---------------------------------------------------------------------+ ' | When this subroutine is called, the top and bottom | ' | rows are displayed. | ' +---------------------------------------------------------------------+ COLOR TBColrFG%, TBColrBG% LOCATE ULRow% - 1, 1, 0, 0, 0 PRINT SPACE$(LRCol% - ULCol% + 1); LOCATE ULRow% - 1, 31, 0, 0, 0 PRINT CHR$(240) + " TrueView Program " + CHR$(240); LOCATE ULRow% - 1, 62, 0, 0, 0 PRINT "Top Line:"; LOCATE ULRow% - 1, 2, 0, 0, 0 PRINT "File: " + ComFile$ LOCATE LRRow% + 1, 1, 0, 0, 0 PRINT SPACE$(LRCol% - ULCol% + 1); LOCATE LRRow% + 1, 2, 0, 0, 0 PRINT "EXIT: MOVE: "; LOCATE LRRow% + 1, 21, 0, 0, 0 PRINT "<" + CHR$(24) + "> <" + CHR$(25) + "> "; LOCATE LRRow% + 1, 59, 0, 0, 0 PRINT "Bottom Line: "; COLOR FGColr%, BGColr% RETURN da.end.james: ' +---------------------------------------------------------------------+ ' | when the end of a file is reached, the | ' | program branches to this procedure: | ' +---------------------------------------------------------------------+ EndYes% = 1: EndPg% = 1 COLOR TBColrFG%, TBColrBG% LOCATE 1, 22, 0, 0, 0: PRINT "- Please Wait -" + SPACE$(14) DownUp& = 0 EndOfFile% = 0 FileEnd% = 0 CountLines& = 0 CLOSE #1 OPEN FileName$ FOR INPUT AS #1 DO LINE INPUT #1, ThrowAway$ IF EOF(1) THEN EXIT DO CountLines& = CountLines& + 1 LOOP UNTIL EOF(1) CLOSE #1 OPEN FileName$ FOR INPUT AS #1 FOR LastScrn& = 1 TO CountLines& + 1 - (LRRow% - ULRow% + 1) IF EOF(1) THEN EXIT FOR END IF LINE INPUT #1, M$ IF RTRIM$(LTRIM$(M$)) = CHR$(12) THEN M$ = SPACE$(80) M$ = LEFT$(M$, 80) ManyLines& = ManyLines& + 1 COLOR TBColrFG%, TBColrBG% LOCATE 1, 40, 0, 0, 0: PRINT "Loading:"; LOCATE 1, 49, 0, 0, 0: PRINT RTRIM$(LTRIM$(STR$(ManyLines&))); NEXT GOSUB paint.top.bottom FOR TheLastScrn% = ULRow% TO LRRow% IF EOF(1) THEN EXIT FOR END IF LINE INPUT #1, M$ IF RTRIM$(LTRIM$(M$)) = CHR$(12) THEN M$ = SPACE$(80) M$ = LEFT$(M$, 80) COLOR FGColr%, BGColr% LOCATE TheLastScrn%, ULCol%, 0, 0, 0 PRINT SPACE$(LRCol% - ULCol% + 1); LOCATE TheLastScrn%, ULCol%, 0, 0, 0 PRINT M$; NEXT CLOSE #1 DownUp& = CountLines& - (LRRow% - ULRow% + 1) + 1 COLOR TBColrFG%, TBColrBG% LOCATE 1, 22, 0, 0, 0: PRINT " - TrueView Program - "; COLOR FGColr%, BGColr% ManyLines& = 0 RETURN home.james: ' +---------------------------------------------------------------------+ ' | when the top of a file is reached, the program | ' | branches to this subroutine: | ' +---------------------------------------------------------------------+ CLOSE #1 OPEN FileName$ FOR INPUT AS #1 FOR HomePage% = ULRow% TO LRRow% IF EOF(1) THEN EXIT FOR END IF LOCATE HomePage%, ULCol%, 0, 0, 0 PRINT SPACE$(LRCol% - ULCol% + 1); LINE INPUT #1, M$ IF RTRIM$(LTRIM$(M$)) = CHR$(12) THEN M$ = SPACE$(80) M$ = LEFT$(M$, 80) LOCATE HomePage%, ULCol%, 0, 0, 0 PRINT M$; NEXT DownUp& = 1 GOSUB paint.top.bottom RETURN save.true.screen: ' +---------------------------------------------------------------------+ ' | When the program asks for GOSUB save.screen, the following | ' | six lines saves the screen from row 2 to row 24: | ' +---------------------------------------------------------------------+ REDIM ReadLine$(25) FOR ViewIt% = SR.UL.Row% TO SR.LR.Row% FOR Horizon% = SR.UL.Col% TO SR.LR.Col% ReadLine$(ViewIt%) = ReadLine$(ViewIt%) + CHR$(SCREEN(ViewIt%, Horizon%)) NEXT NEXT restore.true.screen: ' +---------------------------------------------------------------------+ ' |This subroutine restores the above saved screen, except the saved | ' |screen is moved either up or down. If the down arrow is pressed, then| ' |DnAr% = 1 and the saved screen is moved up one place and a new line | ' |is brought in and displayed at row 24. If the up arrow is pressed, | ' |then UpAr% = 1 and the saved screen is moved down one row and a new | ' |line is displayed at row 2, just under the top linebar. | ' +---------------------------------------------------------------------+ IF DnAr% = 1 THEN StartSite% = SR.UL.Row% - 1 StopSite% = SR.LR.Row% - 1 ELSEIF UpAr% = 1 THEN StartSite% = SR.UL.Row% + 1 StopSite% = SR.LR.Row% + 1 END IF FOR FindRow% = StartSite% TO StopSite% LOCATE FindRow%, SR.UL.Col%, 0, 0, 0 PRINT SPACE$(LRRow% - ULRow% + 1); LOCATE FindRow%, SR.UL.Col%, 0, 0, 0 COLOR FGColr%, BGColr% IF DnAr% = 1 THEN PRINT ReadLine$(FindRow% + DnAr%); ELSEIF UpAr% = 1 THEN PRINT ReadLine$(FindRow% - UpAr%); END IF NEXT ERASE ReadLine$ RETURN END SUB