home *** CD-ROM | disk | FTP | other *** search
/ PC-Blue - MS DOS Public Domain Library / PC-Blue MS-DOS Public Domain Library - NYACC.iso / vol046 / sample.bas < prev    next >
Encoding:
BASIC Source File  |  1987-01-11  |  2.4 KB  |  59 lines

  1. 10 ' *********************************************************************
  2. 20 ' *   PC-File Sample program.                                         *
  3. 30 ' *********************************************************************
  4. 40 ' *
  5. 50 ' *  This program reads a sample database, in sequence by the most
  6. 60 ' *  recent sort (in sequence by Index). For each record read, a line
  7. 70 ' *  is printed on the printer.
  8. 80 ' *  The name of the database is "SAMPLE".
  9. 90 ' *
  10. 100 '* The sample file was defined as follows:
  11. 110 '*    NAM          20
  12. 120 '*    ADDRESS      25
  13. 130 '*    CITY         12
  14. 140 '*    STATE         2
  15. 150 '*    ZIP           5
  16. 160 '*                ---
  17. 170 '*                 64  (total length of data fields)
  18. 180 '*
  19. 190 '* The length of an index record is therefore:
  20. 200 '*    2 * (number of fields) + 4,  or
  21. 210 '*    2 * 5 + 4 = 14
  22. 220 '*
  23. 230 '* The length of a data record is:
  24. 240 '*    Length of data fields + 1,  or
  25. 250 '*    64 + 1 = 65
  26. 260 '
  27. 270 '* NOTE: if record length is longer than 128, then you must start BASIC
  28. 280 '*       with the /S:512 option. See page 2-4 in your BASIC manual.
  29. 285 '
  30. 286 END ' This is here because some people INSIST on trying to RUN this!
  31. 287 '     You'll want to put it elsewhere in a production program.
  32. 290 '....................................................................
  33. 300 '    DATA INITIALIZATION
  34. 310 '
  35. 320 INX.LEN = 14
  36. 330 DTA.LEN = 65
  37. 340 '....................................................................
  38. 350 '     OPEN FILES FOR PROCESSING
  39. 360 '
  40. 370 OPEN "SAMPLE.INX" AS #1 LEN=INX.LEN
  41. 380 FIELD #1, 10 AS X.INX$, 4 AS POINTER.INX$
  42. 390 OPEN "SAMPLE.DTA" AS #2 LEN=DTA.LEN
  43. 400 FIELD #2, 20 AS NAM$, 25 AS ADDRESS$, 12 AS CITY$, 2 AS STATE$, 5 AS ZIP$
  44. 410 '...................................................................
  45. 420 '     READ AND PROCESS THE DATA
  46. 430 '
  47. 440 GET #1 '                                     GET NXT SEQUENTIAL INX RCD
  48. 450 IF LEFT$(X.INX$,1) = "/" THEN 440 '          DELETED RECORD
  49. 460 IF LEFT$(X.INX$,1) = "\" THEN 510 '          END OF FILE
  50. 470 POINTER = VAL(POINTER.INX$) '                GET POINTER INTO DATA FILE
  51. 480 GET #2,POINTER '                             RANDOM RETRIEVE DTA RECORD
  52. 490 LPRINT NAM$;" ";ADDRESS$;" ";CITY$;" ";STATE$;" ";ZIP$
  53. 500 GOTO 440
  54. 510 '...................................................................
  55. 520 '      PROCESSING IS COMPLETED. SHUTDOWN.
  56. 530 '
  57. 540 CLOSE
  58. 550 END
  59.