4000	REM	QSO LOG
	TPYFILE$="QSOSORT.FIL"
	FILE	TPYFILE$
	DIM CALL$(50),NAME$(50),QTH$(50),FREQ$(50),DATE$(50),TIME$(50),CARD$(50)
	ONE=1
	CNT=ONE
	PRINT CHR$(26)
	PRINT  "START OF UPDATE"
	INPUT "What date is today? (YYMMDD) ";TODAY$
 
4050	REM DATA ENTRY
	INPUT "Enter call sign ";CALL$(CNT)
	IF CALL$(CNT)="END" OR CALL$(CNT)="End" THEN 4200
	IF MID$(CALL$(CNT),2,1) < CHR$(58) THEN\
		CALL$(CNT)=LEFT$(CALL$(CNT),1)+CHR$(32)+MID$(CALL$(CNT),2,7)+" "
	INPUT "Enter name";NAME$(CNT)
	INPUT "Enter QTH ";QTH$(CNT)
	INPUT "Enter frequency worked ";FREQ$(CNT)
	INPUT "Enter date worked (if today enter 'P')";DATE$(CNT)
	IF DATE$(CNT)="P" THEN DATE$(CNT)=TODAY$
	INPUT "Enter time EST";TIME$(CNT)
	INPUT "Enter if QSL card was mailed (Y/N)";CARD$(CNT)
	PRINT
	PRINT CNT
	PRINT CALL$(CNT),NAME$(CNT),QTH$(CNT)
	PRINT FREQ$(CNT),DATE$(CNT),TIME$(CNT),CARD$(CNT)
	PRINT
 
4090	REM
	INPUT "ACCEPT(Y) ELSE REJECT(N): "; ANS$
	IF ANS$="Y" THEN 4100
	IF ANS$="N" THEN 4050
	PRINT "PLS ENTER CORRECT OPTION"
	GOTO 4090
 
4100	REM	BUMP UP COUNT
	PRINT "RECORD ACCEPTED"
	PRINT
	CNT=CNT+1
	GOTO 4050
 
4200	REM COUNT UP AND SORT
	CNT=CNT-1
	PRINT CNT;"ITEMS ENTERED"
	OFF=0
	SET=1
	TWO=2
	FILLER$="                        "
	PRINT "SORTING...",
 
 
4500	REM   SORT
	LASTCNT=CNT-1
	IF LASTCNT=0 THEN 4900
	CNT=1
	FLAG=OFF
 
4550	REM SORT ITERATION
	C$=CALL$(CNT)+FILLER$
	C$=LEFT$(C$,1)+MID$(C$,3,7)
	IF LEFT$(C$,1)="K" OR LEFT$(C$,1)="N" OR LEFT$(C$,1)="A" \
		OR LEFT$(C$,1)="W" THEN C$=MID$(C$,2,5)+FILLER$
	NAME1$=C$
	C$=CALL$(CNT+1)+FILLER$
	C$=LEFT$(C$,1)+MID$(C$,3,7)
	IF LEFT$(C$,1)="K" OR LEFT$(C$,1)="N" OR LEFT$(C$,1)="A" \
		OR LEFT$(C$,1)="W" THEN C$=MID$(C$,2,5)+FILLER$
	NAME2$=C$
	IF NAME1$ <= NAME2$ THEN 4600
	GOSUB 4700
 
4600	CNT=CNT+1
	IF CNT >LASTCNT THEN 4800
	GOTO 4550
 
4700	REM   SWAP FIELDS
	ZCALL$=CALL$(CNT)
	ZNAME$=NAME$(CNT)
	ZQTH$=QTH$(CNT)
	ZFREQ$=FREQ$(CNT)
	ZDATE$=DATE$(CNT)
	ZTIME$=TIME$(CNT)
	ZCARD$=CARD$(CNT)
 
	CALL$(CNT)=CALL$(CNT+1)
	NAME$(CNT)=NAME$(CNT+1)
	QTH$(CNT)=QTH$(CNT+1)
	FREQ$(CNT)=FREQ$(CNT+1)
	DATE$(CNT)=DATE$(CNT+1)
	TIME$(CNT)=TIME$(CNT+1)
	CARD$(CNT)=CARD$(CNT+1)
 
	CALL$(CNT+1)=ZCALL$
	NAME$(CNT+1)=ZNAME$
	QTH$(CNT+1)=ZQTH$
	FREQ$(CNT+1)=ZFREQ$
	DATE$(CNT+1)=ZDATE$
	TIME$(CNT+1)=ZTIME$
	CARD$(CNT+1)=ZCARD$
 
	FLAG=SET
	RETURN
 
4800	REM	CHECK END OF SORT
	IF FLAG=OFF THEN 4900
	FLAG=OFF
	CNT=ONE
	GOTO 4550
 
4900	REM   WRITE OUT SORTED FILE
	FOR CNT=1 TO LASTCNT+1
	PRINT #ONE; CALL$(CNT),NAME$(CNT),QTH$(CNT),FREQ$(CNT),\
	DATE$(CNT),TIME$(CNT),CARD$(CNT)
	PRINT CALL$(CNT),
	NEXT CNT
	PRINT #ONE; "END","END","END","END","END","END","END"
	CLOSE 1
