10 ' THIS SORT PROGRAM ADAPTED FROM PAGE 126 INTERFACE AGE
20 ' JULY 1980 / ADDITIONS BY, HANK SZYSZKA
30 ' WRITTEN BY ALAN R. MILLER
40 ' IMPROVEMENTS:
50 '	VARIABLE COLUMNS FOR SORT BY INPUT STATEMENT
60 '	RESORT OPTION AFTER MATRIX IS LOADED AND AFTER
70 '	  FIRST SORT IS COMPLETED.
80 '	ADDITIONAL FILES OPTIONAL BEFOR TERMINATION.
90 PRINT CHR$(27);"*              "
100 RESET
110 CLEAR 2500
120 DEFINT I-N
130 DIM A$(500)
140 '
150 PRINT
160 PRINT "Enter file names in upper case-letters."
170 PRINT "FILE NAMES NEED NOT BE EMBEDDED IN QUOTES."
180 PRINT
190 INPUT "WHAT IS THE NAME OF THE ORIGINAL FILE";OLD$
200 INPUT "WHAT NAME DO YOU WANT FOR THE NEW FILE";NW$
210 INPUT "ENTER SORT COLUMNS A,B ";A,B
220 '
230 OPEN "I",#2,OLD$:I=0
240 '
250 IF EOF(2) THEN 300
260 I=I+1
270  LINE INPUT #2,A$(I)
280 GOTO 250
290 '
300 N=I
310 PRINT: PRINT "   ";N;" RECORDS READ."
320 '
330 ' THIS STARTS THE ACTUAL SORT
340 '
350 PRINT: PRINT "STARTING SORT ON COL'S ";A;" THRU ";A+B-1
360 J4=N
370 J4=J4\2
380 IF J4=0 THEN 540 'DONE
390 J2=N-J4
400 J=1
410 I=J
420 J3=I+J4
430 '
440 ' SORTING COLUMNS ARE DETERMINED BY  A,B  IN MID$() COMMAND
450 ' THESE VALUES ARE A= STARTING COLUMN B= NUMBER OF COLUMNS.
460 '
470 IF MID$(A$(I),A,B) <= MID$(A$(J3),A,B) THEN 510
480 SWAP A$(I),A$(J3)
490 I=I-J4
500 IF I>=1 THEN 420
510 J=J+1
520 IF J>J2 THEN 370
530 GOTO 410
540 PRINT "SORT COMPLETED.."
550 OPEN "O",#1,NW$
560 PRINT "WRITING FILE TO DISK FILE ";NW$
570 '
580 ' WRITE SORTED DATA TO DISK
590 FOR I=1 TO N
600 PRINT #1,A$(I)
610 NEXT I
620 CLOSE #1
630 '
640 ' PRINT SORTED FILE ON CONSOLE
650 '
660 FOR I=1 TO N
670 PRINT A$(I)
680 NEXT I
690 '
700 PRINT:INPUT "WANT TO SORT THE FILE INTO ANOTHER SEQUENCE ? ";AN$
710 IF AN$="YES" THEN GOTO 720 ELSE CLOSE : END
720 INPUT "WHAT NAME DO YOU WANT FOR THE NEW FILE";INW$
730 IF LEN(INW$)<>0 THEN NW$=INW$: PRINT "NEW FILE ";NW$
740 INPUT "ENTER SORT COLUMNS A,B ";A,B
750 GOTO 330
W FILE";INW$
730 IF LEN(INW$)<>0 THEN NW$