* PURGE.CMD
* M. Lynn
* Version 1.6
STORE T TO ok
STORE '80' TO myear
IF file = '1'
STORE 'PER' TO macc
ELSE
STORE 'BUS' TO macc
ENDIF

DO WHILE OK
@ 16, 3 SAY 'For what year would you like to archive entries in'
@ 17, 3 SAY 'the '+maccount+' Checkbook?'
@ 18, 3 SAY 'Enter 00 to abort this command ----' GET myear PICTURE '99'
READ
@ 16, 0 SAY '|                                                                 |'
@ 17, 0 SAY '|                                                                 |'
@ 18, 0 SAY '|                                                                 |'

IF myear = '00'
RELEASE ok, macc, myear, drive, dbf, more
RETURN
ELSE

	IF myear = year
	@ 16, 3 SAY 'It looks to me as if you want to archive the checks for the'
	@ 17, 3 SAY 'currrent year, which is not something I really want to do.'
	@ 18, 3 SAY 'If however you really do want to do that, go back to the'
	@ 19, 3 SAY 'main menu and change the system date to some other year.'
	@ 20, 3 SAY 'Please try again. -- Enter any character -- '
	SET CONSOLE OFF
	WAIT
	SET CONSOLE ON

	@ 16, 0 SAY '|                                                                 |'
	@ 17, 0 SAY '|                                                                 |'
	@ 18, 0 SAY '|                                                                 |'
	@ 19, 0 SAY '|                                                                 |'
	@ 20, 0 SAY '|                                                                 |'
	LOOP

	ENDIF
ENDIF

LOCATE FOR $(date,7,2) = myear

	IF EOF
	@ 16, 3 SAY 'There are no records in the database from'
	@ 17, 3 SAY 'that year.  Enter any character to continue'
	SET CONSOLE OFF
	WAIT
	SET CONSOLE ON
	@ 16, 0 SAY '|                                                                 |'
	@ 17, 0 SAY '|                                                                 |'	
	LOOP
	ENDIF


@ 16, 3 SAY 'Enter a single letter for the drive you wish to use to store'
@ 17, 3 SAY 'this a database: '
SET CONSOLE OFF
WAIT TO drive
SET CONSOLE ON
@ 16, 0 SAY '|                                                                 |'
@ 17, 0 SAY '|                                                                 |'

	DO CASE

	CASE !(drive) = 'A'

	CASE !(drive) = 'B'
	IF maxdrive < 2
	@ 16, 3 SAY 'That is an ilegal drive'
	@ 18, 3 SAY 'Enter any character to try again'
	SET CONSOLE OFF
	WAIT
	SET CONSOLE ON
	@ 16, 0 SAY '|                                                                 |'
	@ 18, 0 SAY '|                                                                 |'
	LOOP
	ENDIF

	CASE !(drive) = 'C'
	IF maxdrive < 3
	@ 16, 3 SAY 'That is an ilegal drive'
	@ 18, 3 SAY 'Enter any character to try again'
	SET CONSOLE OFF
	WAIT
	SET CONSOLE ON
	@ 16, 0 SAY '|                                                                 |'
	@ 18, 0 SAY '|                                                                 |'
	LOOP
	ENDIF

	CASE !(drive) = 'D'
	IF maxdrive < 4
	@ 16, 3 SAY 'That is an ilegal drive'
	@ 18, 3 SAY 'Enter any character to try again'
	SET CONSOLE OFF
	WAIT
	SET CONSOLE ON
	@ 16, 0 SAY '|                                                                 |'
	@ 18, 0 SAY '|                                                                 |'
	LOOP
	ENDIF

	CASE !(drive) = 'E'
	IF maxdrive < 5
	@ 16, 3 SAY 'That is an ilegal drive'
	@ 18, 3 SAY 'Enter any character to try again'
	SET CONSOLE OFF
	WAIT
	SET CONSOLE ON
	@ 16, 0 SAY '|                                                                 |'
	@ 18, 0 SAY '|                                                                 |'
	LOOP
	ENDIF

	OTHERWISE
	@ 16, 3 SAY 'That is an illegal drive'
	@ 18, 3 SAY 'Enter any character to try again'
	SET CONSOLE OFF
	WAIT
	SET CONSOLE ON
	@ 16, 0 SAY '|                                                                 |'
	@ 18, 0 SAY '|                                                                 |'
	LOOP

	ENDCASE # drive

STORE drive+':'+myear+macc TO dbf

	IF FILE (dbf)
	@ 16, 3 SAY 'File '+dbf+' already exisits'
	@ 17, 3 SAY 'This operation will overwrite '+dbf
	@ 18, 3 SAY 'Enter a Y to continue or any other character to abort: (Y/N)'
	SET CONSOLE OFF
	WAIT TO more
	SET CONSOLE ON
	@ 16, 0 SAY '|                                                                 |'
	@ 17, 0 SAY '|                                                                 |'
	@ 18, 0 SAY '|                                                                 |'

		IF !(more) # 'Y'
		RELEASE ok, macc, myear, drive, dbf, more		
		RETURN
		ENDIF
	ENDIF

@ 16, 3 SAY 'Copying records for 19'+myear+' to '+dbf
COPY TO &dbf FOR $(date,7,2) = myear
USE &maccount
@ 16, 0 SAY '|                                                                 |'
@ 16, 3 SAY 'Deleting records for 19'+myear+' from '+maccount
DELETE ALL FOR $(date,7,2) = myear
@ 16, 0 SAY '|                                                                 |'
@ 16, 3 SAY 'Packing '+maccount
PACK

	IF file = '1'
	@ 16, 0 SAY '|                                                                 |'
	@ 16, 3 SAY 'Indexing '+maccount+' on the memo field'
	INDEX ON MEMO TO PERSONAL
	@ 16, 0 SAY '|                                                                 |'
	@ 16, 3 SAY 'Indexing '+maccount+' on the number field'
	INDEX ON NUMBER TO INDPERNO
	ELSE
	@ 16, 0 SAY '|                                                                 |'
	@ 16, 3 SAY 'Indexing '+maccount+' on the memo field'
	INDEX ON MEMO TO BUSINESS
	@ 16, 0 SAY '|                                                                 |'
	@ 16, 3 SAY 'Indexing '+maccount+' on the number field'
	INDEX ON NUMBER TO INDBUSNO
	ENDIF

STORE F TO ok	
ENDDO # ok
RELEASE ok, macc, myear, drive, dbf, more
RETURN
field'
	INDEX ON NUMBER TO INDBUSNO
	ENDIF

STORE F TO ok	
ENDDO # ok
RELEASE ok, macc, myear, drive, dbf, more
RETUR