home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / tutor / pro17 / student.bas < prev    next >
Encoding:
BASIC Source File  |  1991-03-29  |  2.7 KB  |  74 lines

  1. 10 'STUDENT.BAS - From the GWBT (GW-Basic Tutorial) Series
  2. 20 'Lesson 10, 04/01/1991  Illustrating the use of RANDOM file types
  3. 30 '
  4. 40 'We are dealing with a set of data as shown:
  5. 50 '
  6. 60 'SNAME$ - Student last name, 18 alphabetic characters
  7. 70 'STUDENTID# - Student ID Code
  8. 80 'COURSECODE% - Student's Course ID Code
  9. 90 'GPA! - Student's Grade Point Average
  10. 100 '
  11. 110 'We'll be storing these in a RANDOM disk file in that order:
  12. 120 '
  13. 130 OPEN "STUDENT.DAT" FOR RANDOM AS #1 LEN=32
  14. 140 FIELD #1,18 AS STUDNAME$,8 AS STUDID$,2 AS STUDCC$,4 AS STUDGPA$
  15. 150 '
  16. 160 'NOTE that all the fields are set up as STRINGS - This is how we will be
  17. 170 'storing the information to disk following the conversion...
  18. 180 '
  19. 190 KEY OFF:COLOR 6,0,0:CLS
  20. 200 PRINT "Press 'R' to read in a student's information from disk, 'W' to"
  21. 210 PRINT "enter and write a student's information to disk, or 'Q' to quit..."
  22. 220 AA$=INKEY$
  23. 230 IF AA$="Q" OR AA$="q" THEN CLOSE:RESET:END
  24. 240 IF AA$="R" OR AA$="r" THEN GOTO 300
  25. 250 IF AA$="W" OR AA$="w" THEN GOTO 520
  26. 260 GOTO 220
  27. 270 'The above will end the program if Q is pressed, go to line 300 or 400 as
  28. 280 'above; if the key is not Q, R, or W it will go back to 220 and get another
  29. 290 'key press...
  30. 300 'Choice = "R" (Read in Student Information)
  31. 310 CLS
  32. 320 PRINT "To find a student's information on disk, I need you to give me the"
  33. 330 PRINT "Student ID code.  Please enter it below..."
  34. 340 PRINT
  35. 350 INPUT "Student ID: ",STUDENTID#
  36. 360 PRINT
  37. 370 PRINT "Looking, please wait..."
  38. 380 EN1=LOF(1)/32
  39. 390 FOR RECORD = 1 TO EN1
  40. 400 GET #1,RECORD
  41. 410 SID# = CVD(STUDID$)
  42. 420 IF SID# <> STUDENTID# THEN GOTO 480
  43. 430 PRINT "Information is as follows:"
  44. 440 PRINT "Student Last Name: ";STUDNAME$
  45. 450 PRINT "Student ID Code  : ";SID#
  46. 460 PRINT "Course Code      : ";CVI(STUDCC$)
  47. 470 PRINT "Student GPA      : ";CVS(STUDGPA$)
  48. 480 NEXT RECORD
  49. 490 PRINT "Search complete.  Press any key to continue..."
  50. 500 WHILE INKEY$="":WEND
  51. 510 GOTO 190
  52. 520 'Choice - "W" (Write information to disk)
  53. 530 PRINT
  54. 540 PRINT "Please provide the requested information below..."
  55. 550 PRINT
  56. 560 LINE INPUT "Student Last Name: ";SNAME$
  57. 570 INPUT "Student ID Code  : ";STUDENTID#
  58. 580 INPUT "Course Code      : ";COURSECODE%
  59. 590 INPUT "Student GPA      : ";STUDENTGPA!
  60. 600 PRINT
  61. 610 PRINT "If all of the above is correct, press 'Y' to save to disk, or else
  62. 620 PRINT "press 'N' to start over again..."
  63. 630 AA$=INKEY$
  64. 640 IF AA$="Y" OR AA$="y" THEN GOTO 670
  65. 650 IF AA$="N" OR AA$="n" THEN GOTO 540
  66. 660 GOTO 630
  67. 670 EN1=LOF(1)/32 + 1
  68. 680 LSET STUDNAME$ = SNAME$
  69. 690 LSET STUDID$ = MKD$(STUDENTID#)
  70. 700 LSET STUDCC$ = MKI$(COURSECODE%)
  71. 710 LSET STUDGPA$=MKS$(STUDENTGPA!)
  72. 720 PUT #1,EN1
  73. 730 GOTO 190
  74.