20 PRINT"This is the RE-KEY utility program for CREATOR data files.":PRINT:PRINT
30 PRINT"This program will allow you to do the following:"
40 PRINT"1. Repair a damaged key file."
50 PRINT"2. Create a new key file for a field not previously a key."
60 PRINT"3. Create added keys for records you may have appended to an":PRINT" existing data file."
70 PRINT:PRINT"You must be able to tell me a few things about your data file."
80 PRINT"For example, the record length, the beginning position and":PRINT"length of the key field, and the maximum number of records":PRINT"allowed in the file. Of course, you must know the name of the"
90 PRINT"data file, as well. DEPRESS ANY KEY TO CONTINUE: ";
100 AN$=INKEY$:IF AN$="" THEN 100
110 PRINT"You may not use a packed field as a key field. Record length":PRINT"can be up to 256, key length up to 255.":PRINT"When I ask for file names, please give the complete file name,":PRINT"including the . type and drive!"
120 PRINT:PRINT"Now give me the complete DATA file name: ";
130 LINE INPUT DF$:IF DF$<"A" OR LEN(DF$)>14 THEN PRINT"Illegal name!":GOTO 120
140 PRINT"Now tell me the maximum number of records allowed in this":PRINT"file, per data disk: ";
150 LINE INPUT MR$:IF VAL(MR$)<1 OR VAL(MR$)>32767 THEN PRINT"Illegal number of records!":GOTO 140
160 PRINT"What is the record length of each record in the data file:";:LINE INPUT RL$
170 IF VAL(RL$)>256 OR VAL(RL$)<1 THEN PRINT"Illegal record length!":GOTO 160
180 PRINT"What is the name of the proposed KEY file? ";:LINE INPUT KF$
190 IF KF$<"A" OR LEN(KF$)>14 THEN PRINT"Illegal key file name!":GOTO 180
200 PRINT"What is the beginning position of the key field in the data":PRINT"record? THIS IS NOT USUALLY THE FIELD NUMBER! ";
210 LINE INPUT ST$:IF VAL(ST$)<1 OR VAL(ST$)>VAL(RL$) THEN PRINT"Illegal starting position: should be from 1 to";VAL(RL$):GOTO 200
220 PRINT"What is the length of the key field: ";:LINE INPUT KL$:IF VAL(KL$)<1 OR VAL(KL$)>255 OR VAL(KL$)>VAL(RL$) THEN PRINT"Illegal key length!":GOTO 220
230 OPEN"R",1,DF$,VAL(RL$)
240 OPEN"R",2,KF$,2
250 FIELD #1,VAL(ST$)-1 AS D$,VAL(KL$) AS K$
260 RL%=VAL(RL$):IF RL%>255 THEN RL%=255
270 FIELD #1,RL% AS B$
280 MR%=VAL(MR$)
290 DIM R%(MR%):FOR I%=1 TO MR%:R%(I%)=-1:NEXT I%:I%=1:KL%=VAL(KL$)
300 LSET B$=STRING$(RL%,250):PUT 1,1:PRINT"RE-KEYING THROUGH RECORD NUMBER ";
310 I%=I%+1:GET 1,I%:F%=KL%:IF B$=STRING$(RL%,0) THEN 420
320 PRINT I%;
340 IF K$<CHR$(250) THEN 390
350 RP=MS*RND
360 RP=RP+1:IF RP>MR% OR RP<2 THEN RP=2
370 IF R%(RP)<>-1 THEN 360
380 R%(RP)=-I%:GOTO 310
390 ZZ$=LEFT$(K$,F%):GOSUB 460
400 RP=RP+1:IF RP>MR% OR RP<2 THEN RP=2
410 IF R%(RP)=-1 THEN R%(RP)=I%:GOTO 310:ELSE 400
420 CLOSE 1:PRINT:PRINT"WRITING KEY POINTERS NOW."
430 FIELD #2,2 AS KP$
440 R%(1)=I%-1:FOR I%=1 TO MR%:LSET KP$=MKI$(R%(I%)):PUT 2,I%:NEXT
450 PRINT:PRINT"RE-KEY OPERATION IS COMPLETE.":END