10 ' 6 sept 86    GRID.BAS
20 '
30 '    ***** NOT FOR COMMERCIAL USE *****
40 '		Bob Bruner
50 '		P. O. Box 392
60 '		El Cerrito, CA 94530
70 '
80 '  draw a grid, specified numbers of columns and rows
90 ' ordinary printing characters only, no special hardware requirements
100 '
110 ' ***** USER INSTALLATION AREA *****
120 ' user may adjust values in following lines as desired
130 ' (down to next *****)
140 '
150 ' (Values supplied in distributed version are also listed in
160 '  remark statements before each group, for reference.)
170 '
180 ' characters to make grid lines
190 ' (distributed version: |, -  (hyphen), and a blank)
200 VERT$ = "|"
210 HORIZ$ = "-"
220 BLANK$ = " "	' one blank 
230 '
240 '  printer characteristics
250 ' (distributed version: 10, 6 -- standard pica type)
260 ' CPI = Characters Per Inch (horizontal)
270 CPI = 10
280 ' LPI = Lines Per Inch (vertical)
290 LPI = 6
300 '  Distributed version: PRINTERINIT$ = ""  (null string). Leave it
310 '  that way unless you have a reason to change it. See Technical
320 '  Notes in DOC file. Make sure that preceding variables (CPI, LPI)
330 '  agree with the result of any init string you do use.
340 PRINTERINIT$ = ""
350 '
360 ' page parameters, all in inches
370 '    If these values result in graph width or height which is negative,
380 '    there will be a message when program is run, to check installation.
390 ' (distributed version: 8.5, 1.5, 1.5, 11, 1.5, 1.5; that is 8 1/2
400 '  by 11 inch paper,  with 1 1/2 inch margins all around.)
410 PAGEWIDTH = 8.5
420 LEFTMARGIN = 1.5
430 RIGHTMARGIN = 1.5
440 PAGEHEIGHT = 11
450 TOPMARGIN = 1.5
460 BOTTOMMARGIN = 1.5
470 '
480 ' ***** END USER INSTALLATION AREA *****
490 '
500 ' introduction
510 PRINT : PRINT
520 PRINT "This program draws a uniform grid, with specified numbers"
530 PRINT "of columns and rows."
540 PRINT
550 PRINT "If the printer characteristics or page layout do not suit you,"
560 PRINT "see installation information near top of program, or in DOC file."
570 '
580 ' how many columns and rows?
590 PRINT : PRINT
600 PRINT "How many columns";
610 GOSUB 1250	'entry
620 COLUMNS% = ENTRY
630 PRINT
640 PRINT "How many rows";
650 GOSUB 1250	'entry
660 ROWS% = ENTRY
670 PRINT : PRINT
680 '
690 ' calculated values, horizontal
700 LEFTCHAR% = LEFTMARGIN*CPI	'left margin, in characters
710 LEFTSPACE$ = STRING$(LEFTCHAR%,BLANK$)	'a string to print left margin 
720 HORINCHES=PAGEWIDTH-(LEFTMARGIN+RIGHTMARGIN)	' allowed HORizontal size of graph, INCHES
730 IF HORINCHES <= 0 THEN PRINT "Requested graph width is negative. Check installation." : GOTO 1400 ' end
740 HORCHAR = HORINCHES * CPI	' HOR size, CHARacters
750 COLWIDTH% = (HORCHAR-1)/COLUMNS%		'col width, in characters;
760 '	-1 above is because there is one more border line than column
770 IF COLWIDTH% = 0 THEN PRINT "Too many columns. Won't fit. Start over." : GOTO 590
780 HORIZLINE$ = STRING$(COLWIDTH% * COLUMNS% + 1, HORIZ$)	'one horiz line
790 SPACER$ = STRING$(COLWIDTH% - 1 , BLANK$)	'blank space between vert bars
800 '
810 ' calculated values, vertical
820 TOPLINES% = TOPMARGIN * LPI - 1	' topmargin, in lines (-1 to account
830 '					for printing the init string)
840 VERTINCHES=PAGEHEIGHT-(TOPMARGIN+BOTTOMMARGIN)	' allowed VERTical size of graph, INCHES
850 IF VERTINCHES <= 0 THEN PRINT "Requested graph height is negative. Check installation." : GOTO 1400 ' end
860 VERTCHAR = VERTINCHES * LPI	' VERT size, CHARacters
870 ROWHEIGHT% = (VERTCHAR-1)/ROWS%		'row height, in lines
880 IF ROWHEIGHT% < 2 THEN PRINT "Too many rows. Won't fit. Start over." : GOTO 590
890 '
900 ' draw the grid
910 PRINTER$ = "Y"	' default "Y" sends output to printer; any other value sends output to console
920 PRINT "Check that printer is ready."
930 GOSUB 1310	'continue
940 IF A$ = "C" OR A$ = "c" THEN PRINTER$ = "C"	'output to console
950 IF PRINTER$ = "Y" THEN LPRINT PRINTERINIT$	'init string to set printer
960 ' draw top margin
970 FOR I% = 1 TO TOPLINES%
980	IF PRINTER$ = "Y" THEN LPRINT ELSE PRINT
990 NEXT I%
1000 ' draw top line and middle lines for each row
1010 FOR I% = 1 TO ROWS%	
1020	GOSUB 1110	' horiz line, top of row
1030	FOR J% = 1 TO ROWHEIGHT% - 1
1040		GOSUB 1160	' one line, blank except vertical bars
1050	NEXT J%
1060 NEXT I%
1070 GOSUB 1110	' horiz line, bottom of grid
1080 GOTO 1400	' end main program
1090 '
1100 '   subroutines
1110 ' sub to print a full length horizontal line
1120 IF PRINTER$ = "Y" THEN LPRINT LEFTSPACE$; ELSE PRINT LEFTSPACE$; 'margin
1130 IF PRINTER$ = "Y" THEN LPRINT HORIZLINE$ ELSE PRINT HORIZLINE$
1140 RETURN 	'end sub, horiz
1150 '
1160 ' sub: one line, blank except vertical bars
1170 IF PRINTER$ = "Y" THEN LPRINT LEFTSPACE$; ELSE PRINT LEFTSPACE$;
1180 FOR SI%=1 TO COLUMNS%
1190	IF PRINTER$ = "Y" THEN LPRINT VERT$; ELSE PRINT VERT$;
1200	IF PRINTER$ = "Y" THEN LPRINT SPACER$; ELSE PRINT SPACER$;
1210 NEXT SI%
1220 IF PRINTER$ = "Y" THEN LPRINT VERT$ ELSE PRINT VERT$	'end of line
1230 RETURN 	' end sub, blank
1240 '
1250 ' sub to get entry, validate
1260 INPUT ENTRY
1270 IF ENTRY <> INT(ENTRY) THEN PRINT "Must be integer. Re-enter." : GOTO 1260
1280 IF ENTRY < 1 THEN PRINT "Must be at least 1. Re-enter." : GOTO 1260
1290 RETURN	' end sub for entry
1300 '
1310 ' 7 apr 84 	continue	inkey subroutine
1320 PRINT : PRINT
1330 PRINT TAB(10); "Press any key to continue."	
1340 PRINT TAB(10); "    (or press C to send output to console)"
1350 A$ = INKEY$
1360 IF A$ = "" THEN 1350
1370 IF ASC(A$) = 3 THEN STOP		'ctrl/C trap
1380 PRINT : PRINT
1390 RETURN				'end inkey subroutine
1400 END
 RETURN 	'end sub, horiz
1150 '
1160 ' sub: one liIN = 1.5
460 BOTTOMMARGIN = 1.5
470 '
480 ' ***** END USER INSTALLATION AREA *****
490 '
500 ' introduction
510 PRINT : PRINT
520 PRINT "This program draws a uniform grid, with specified numbers"
530 PRINT "of columns and rows."
540 PRINT
550 PRI