home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / database / creator.lbr / REKEY.BZS / REKEY.BAS
Encoding:
BASIC Source File  |  1987-10-25  |  3.1 KB  |  51 lines

  1. 10 RESET
  2. 20 PRINT"This is the RE-KEY utility program for CREATOR data files.":PRINT:PRINT
  3. 30 PRINT"This program will allow you to do the following:"
  4. 40 PRINT"1. Repair a damaged key file."
  5. 50 PRINT"2. Create a new key file for a field not previously a key."
  6. 60 PRINT"3. Create added keys for records you may have appended to an":PRINT"   existing data file."
  7. 70 PRINT:PRINT"You must be able to tell me a few things about your data file."
  8. 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"
  9. 90 PRINT"data file, as well. DEPRESS ANY KEY TO CONTINUE: ";
  10. 100 AN$=INKEY$:IF AN$="" THEN 100
  11. 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!"
  12. 120 PRINT:PRINT"Now give me the complete DATA file name: ";
  13. 130 LINE INPUT DF$:IF DF$<"A" OR LEN(DF$)>14 THEN PRINT"Illegal name!":GOTO 120
  14. 140 PRINT"Now tell me the maximum number of records allowed in this":PRINT"file, per data disk: ";
  15. 150 LINE INPUT MR$:IF VAL(MR$)<1 OR VAL(MR$)>32767 THEN PRINT"Illegal number of records!":GOTO 140
  16. 160 PRINT"What is the record length of each record in the data file:";:LINE INPUT RL$
  17. 170 IF VAL(RL$)>256 OR VAL(RL$)<1 THEN PRINT"Illegal record length!":GOTO 160
  18. 180 PRINT"What is the name of the proposed KEY file? ";:LINE INPUT KF$
  19. 190 IF KF$<"A" OR LEN(KF$)>14 THEN PRINT"Illegal key file name!":GOTO 180
  20. 200 PRINT"What is the beginning position of the key field in the data":PRINT"record? THIS IS NOT USUALLY THE FIELD NUMBER! ";
  21. 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
  22. 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
  23. 230 OPEN"R",1,DF$,VAL(RL$)
  24. 240 OPEN"R",2,KF$,2
  25. 250 FIELD #1,VAL(ST$)-1 AS D$,VAL(KL$) AS K$
  26. 260 RL%=VAL(RL$):IF RL%>255 THEN RL%=255
  27. 270 FIELD #1,RL% AS B$
  28. 280 MR%=VAL(MR$)
  29. 290 DIM R%(MR%):FOR I%=1 TO MR%:R%(I%)=-1:NEXT I%:I%=1:KL%=VAL(KL$)
  30. 300 LSET B$=STRING$(RL%,250):PUT 1,1:PRINT"RE-KEYING THROUGH RECORD NUMBER ";
  31. 310 I%=I%+1:GET 1,I%:F%=KL%:IF B$=STRING$(RL%,0) THEN 420
  32. 320 PRINT I%;
  33. 340 IF K$<CHR$(250) THEN 390
  34. 350 RP=MS*RND
  35. 360 RP=RP+1:IF RP>MR% OR RP<2 THEN RP=2
  36. 370 IF R%(RP)<>-1 THEN 360
  37. 380 R%(RP)=-I%:GOTO 310
  38. 390 ZZ$=LEFT$(K$,F%):GOSUB 460
  39. 400 RP=RP+1:IF RP>MR% OR RP<2 THEN RP=2
  40. 410 IF R%(RP)=-1 THEN R%(RP)=I%:GOTO 310:ELSE 400
  41. 420 CLOSE 1:PRINT:PRINT"WRITING KEY POINTERS NOW."
  42. 430 FIELD #2,2 AS KP$
  43. 440 R%(1)=I%-1:FOR I%=1 TO MR%:LSET KP$=MKI$(R%(I%)):PUT 2,I%:NEXT
  44. 450 PRINT:PRINT"RE-KEY OPERATION IS COMPLETE.":END
  45. 460 FOR ZZ=1 TO LEN(ZZ$)
  46. 470 SP=ASC(MID$(ZZ$,ZZ,1)):X#=X#+ZZ*(SP+1/SP)
  47. 480 NEXT ZZ
  48. 490 IF X#<1E+17 THEN X#=X#*X#:GOTO 490
  49. 500 SP=ASC(ZZ$)+ASC(RIGHT$(ZZ$,1)):SP=SP-10*(INT(SP/10)):SP=SP+4:X$=STR$(X#):RP=VAL(MID$(X$,SP,4)):X#=0
  50. 510 RP=MR%*RP/9999:RP=FIX(RP):RETURN
  51. ASC(RIGHT$(ZZ$,1)):SP=S