home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 63 / CDACTUAL63.iso / Aplicaciones / DarkBasic / DemoDarkBasic.exe / help / examples / input / exam14.dba < prev    next >
Encoding:
Text File  |  2000-04-09  |  2.0 KB  |  107 lines

  1. Rem * Title  : Sequential File Access
  2. Rem * Author : DBS-LB
  3. Rem * Date   : 1st April 2000
  4. rem ============================================
  5. rem DARK BASIC EXAMPLE PROGRAM 14
  6. rem ============================================
  7. rem This program uses sequential file access
  8. rem --------------------------------------------
  9. dim lee$(10,10)
  10.  
  11. rem 0 = Write Data
  12. rem 1 = Read Data
  13. for mode=0 to 1
  14.  
  15.     rem Clear screen
  16.     cls rgb(rnd(100),rnd(100),rnd(100))
  17.  
  18.     rem Delete file
  19.     if file exist("data.dat") then delete file "data.dat"
  20.     
  21.     rem Write or Read..
  22.     if mode=0
  23.     
  24.         rem Open file for writing
  25.         open to write 1,"data.dat"
  26.     
  27.         rem Write data types
  28.         write byte 1,1 : print 1
  29.         write word 1,2 : print 2
  30.         write long 1,3 : print 3
  31.         write file 1,4 : print 4
  32.         write float 1,5.5 : print 5.5
  33.     
  34.         rem Write matrix of strings
  35.         for x=1 to 10
  36.             for y=1 to 10
  37.                 a$=str$(x)+str$(y)    
  38.                 lee$(x,y)=a$
  39.                 write string 1,a$
  40.             next y
  41.         next x
  42.     
  43.         rem Close file
  44.         close file 1
  45.     
  46.         rem Rename file
  47.         if file exist("store.dat")=0
  48.             rename file "data.dat","store.dat"
  49.         endif
  50.     
  51.     else
  52.     
  53.         rem Move file
  54.         move file "store.dat","data.dat"
  55.     
  56.         rem Open file for reading
  57.         open to read 1,"data.dat"
  58.     
  59.         rem Display data types
  60.         read byte 1,a : print a
  61.         read word 1,a : print a
  62.         read long 1,a : print a
  63.         read file 1,a : print a
  64.         read float 1,a# : print a#
  65.     
  66.         rem Read matrix of strings
  67.         for x=1 to 10
  68.             for y=1 to 10
  69.                 read string 1,a$
  70.                 lee$(x,y)=a$
  71.             next y
  72.         next x
  73.     
  74.         rem Close file
  75.         close file 1
  76.     
  77.         rem Move file back
  78.         move file "data.dat","store.dat"
  79.     
  80.     endif
  81.     
  82.     rem Display matrix of strings
  83.     print
  84.     for x=1 to 10
  85.         for y=1 to 10
  86.             print lee$(x,y);" ";
  87.         next y
  88.         print
  89.     next x
  90.     
  91.     rem Wait for key press
  92.     print
  93.     if mode=0 then print "Press Any Key To Read Data"
  94.     if mode=1 then print "Press Any Key To Exit"
  95.     suspend for key
  96.  
  97. next mode
  98.  
  99. rem Make an empty file if none exist
  100. if file exist("blank.txt")=0
  101.     make file "blank.txt"
  102. endif
  103.  
  104. rem End of program
  105. end
  106.  
  107.