1: 10 ' ********************************************************************* 2: 20 ' * PC-File Sample program. * 3: 30 ' * (C)Copyright 1984 by Jim Button * 4: 40 ' ********************************************************************* 5: 50 ' * 6: 60 ' * This program reads a sample database, in sequence by the most 7: 70 ' * recent sort (in sequence by the Index). For each record read, a 8: 80 ' * line is printed on the printer. 9: 90 ' * The name of the hypothetical database is "SAMPLE". 10: 100 '* 11: 110 '* The sample database was defined as follows: 12: 120 '* NAM 20 13: 130 '* ADDRESS 25 14: 140 '* CITY 12 15: 150 '* STATE 2 16: 160 '* ZIP 5 17: 170 '* --- 18: 180 '* 64 (total length of data fields) 19: 190 '* 20: 200 '* The length of an index record in this database is: 21: 210 '* 2 * (number of fields) + 2, or 22: 220 '* 2 * 5 + 2 = 12 23: 230 '* 24: 240 '* The length of a data record in this database is: 25: 250 '* Length of data fields + 1, or 26: 260 '* 64 + 1 = 65 27: 270 ' 28: 280 '* NOTE: if record length is longer than 128, then you must start BASIC 29: 290 '* with the /S:512 option. See page 2-4 in your BASIC manual. 30: 300 ' 31: 310 END ' This is here because some people INSIST on trying to RUN this! 32: 320 ' You'll want to put it elsewhere in a production program. 33: 330 '.................................................................... 34: 340 ' DATA INITIALIZATION 35: 350 ' 36: 360 INX.LEN = 12 37: 370 DTA.LEN = 65 38: 380 '.................................................................... 39: 390 ' OPEN FILES FOR PROCESSING 40: 400 ' 41: 410 OPEN "SAMPLE.INX" AS #1 LEN=INX.LEN 42: 420 FIELD #1,2 AS XNM$,2 AS XAD$,2 AS XCI$,2 AS XST$,2 AS XZI$,2 AS POINT.INX$ 43: 430 ' Each of the above 2-byte fields contains the first 2 bytes of the 44: 440 ' the corresponding field in the data file. 45: 450 ' The last 2 bytes of the index rcd are a binary pointer 46: 460 ' to the relative record number in the data file. 47: 470 ' 48: 480 OPEN "SAMPLE.DTA" AS #2 LEN=DTA.LEN 49: 490 FIELD #2, 20 AS NAM$, 25 AS ADDRESS$, 12 AS CITY$, 2 AS STATE$, 5 AS ZIP$ 50: 500 '................................................................... 51: 510 ' FOR EACH INDEX RECORD, RETRIEVE THE CORRESPONDING DATA RECORD 52: 520 ' 53: 530 GET #1 ' Get nxt sequential INX rcd 54: 540 IF LEFT$(XNM$,1) = "/" THEN 530 ' Deleted record. Bypass it 55: 550 IF LEFT$(XNM$,1) = "\" THEN 600 ' End of file. 56: 560 POINTER = CVI(POINT.INX$) ' Get pointer into DTA file 57: 570 GET #2,POINTER ' Random retrieve DTA record 58: 580 LPRINT NAM$;" ";ADDRESS$;" ";CITY$;" ";STATE$;" ";ZIP$ 59: 590 GOTO 530 60: 600 '................................................................... 61: 610 ' PROCESSING IS COMPLETED. SHUTDOWN. 62: 620 ' 63: 630 CLOSE 64: 640 END 65: |