'===========================================================================
' Subject: TEXT INSIDE A BOX                  Date: 11-25-95 (23:36)       
'  Author: Jim Broadbent                      Code: QB, QBasic, PDS        
'  Origin: FidoNet QUIK_BAS Echo            Packet: TEXT.ABC
'===========================================================================
' > I am in need of some help. I want to open a text
' > file & place the text from that file with a drawn
' > box. The box's size should be determined by the
' > amount of text from the imported file.

 
'Well one way to do it is to use TEXT graphics.
 
'There are several considerations to take into account.
'These include:
 
'1.  The maximum number of lines (rows) of text to be
'    printed within the box is 21 since we require one
'    row for the top and bottom of the box PLUS a blank
'    line at the top and bottom to look nice.
 
'2.  Similarly the maximum width of a character line
'    is 76 characters (columns)(eliminating 2 for the
'    sides of the box and 2 more for blank spaces at
'    either side.
 
'3.  We shall assume the TEXT file is a sequential file.
'    and we have an 80 column screen.
 
 
'   ***** STEP # 1......develope a BOX Subroutine *****
 
        DECLARE SUB BOX (H!, W!, R!, C!)
 
'       This statement is at start of the main program
 
'       H is the height of the box in rows
'       W is the width of the box in columns
'       R is the row of the upper LHS of the box
'       C is the column of the upper LHS of the box
 
 
'   ***** STEP #2  -  Input the text file, count number of
'                     lines and determine the maximum width
'                     the lines.
 
        SCREEN 0: WIDTH 80
        DIM TEXT$(25)            ' ARBITARY 25 LINES OF TEXT
      
START:
        CLS
        LINEMAX = 0: COLUMNMAX = 0
        LOCATE 9, 19
        PRINT "Enter the filename of the text to be boxed"
        LOCATE 11, 35
        LINE INPUT A$             ' you should make
                                  ' this bulletproof
        
        OPEN A$ FOR INPUT AS #1   ' DITTO for this as well
 
        DO WHILE NOT EOF(1)
           INPUT #1, B$
           LINEMAX = LINEMAX + 1
           IF LINEMAX > 21 THEN     ' Too many lines
              LINEMAX = LINEMAX - 1
              EXIT DO
           END IF
           CMAX = LEN(B$)            ' You should check to see
                                     ' if it is over 76 chars
 
           IF CMAX > COLUMNMAX THEN COLUMNMAX = CMAX
           TEXT$(LINEMAX) = B$
        LOOP
        CLOSE #1
 
'   ******* STEP #3 - Calculate the H, W, R, C values ******
 
'       Hopefully this will centre the box in the screen
 
        H = LINEMAX + 4          ' We add 4 to take in the lines
                                 ' and spaces of the box
 
        W = COLUMNMAX + 4        ' Add 4 for the 4 extra box chars
 
        R = INT((25 - H) / 2)
        C = INT((80 - W) / 2)
 
        CLS
        CALL BOX(H, W, R, C)     ' Draw the box
 
        FOR I = 1 TO LINEMAX
           LOCATE R + I + 1, C + 2   ' Print text to box
           PRINT TEXT$(I);
        NEXT I
 
        LOCATE 25, 1: PRINT "Do it again <Y/N>? ";
        DO                           ' Do it again?
           A$ = INKEY$
           IF A$ = "Y" OR A$ = "y" THEN EXIT DO
           IF A$ = "N" OR A$ = "n" THEN END
        LOOP
        GOTO START
 
'You should improve it by making the stages bulletproof
'and able to handle file with over 21 lines.

SUB BOX (H, W, R, C)
 
'       MAKE A BOX SUBROUTINE (TEXT FORMAT)
'       H = HEIGHT; W = WIDTH; R = UPPER ROW; C = LHS COLUMN
 
        LOCATE R, C
        PRINT CHR$(201); STRING$(W - 2, 205); CHR$(187)
        FOR L = 1 TO H - 1
        T = L + R
        LOCATE T, C: PRINT CHR$(186)
        LOCATE T, C + W - 1: PRINT CHR$(186)
        NEXT L
        LOCATE R + H, C
        PRINT CHR$(200); STRING$(W - 2, 205); CHR$(188);
 
END SUB

