Page 286 - Learn to Program - Basic-256
P. 286

Chapter 18: Files – Storing Information For Later.                              Page 270







                           This program uses a single text file to help us maintain a list of
                           our friend's telephone numbers.









             1      # phonelist.kbs
             2      # add a phone number to the list and show
             3
             4      filename = "phonelist.txt"
             5
             6      print "phonelist.kbs - Manage your phone list."
             7      do
             8         input "Add, List, Quit (a/l/q)? ",action
             9         if left(lower(action),1) = "a" then call
                    addrecord(filename)
             10        if left(lower(action),1) = "l" then call
                    listfile(filename)
             11     until left(lower(action),1) = "q"
             12     end
             13
             14     subroutine listfile(f)
             15        if exists(f) then
             16           # list the names and phone numbers in the file
             17           open f
             18           print "the file is " + size + " bytes long"
             19           while not eof
             20              # read next line from file and print it
             21              print readline
             22           end while
             23           close
             24        else
             25           print "No phones on file. Add first."
             26        end if



                                                       © 2019 James M. Reneau (CC BY-NC-SA 3.0 US)
   281   282   283   284   285   286   287   288   289   290   291