home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / batch / ebl407.zip / BATDEMO4.BAT < prev    next >
DOS Batch File  |  1990-11-01  |  6KB  |  180 lines

  1. BAT * Sample of advanced EBL-PLUS File I/O ...
  2.  
  3. -Top
  4.   %N = "EBLDATA.TMP"        |* name of database file
  5.  
  6.         *
  7.         * Define a window for text.
  8.         *   Select both color and size (x/y coordinates).
  9.         *
  10.   CLS
  11.   RAM                       |* Some systems need BIOS not RAM compatibility
  12.   COLOR( black on cyan )
  13.   WINDOW( 10, 1, 70, 8, Double)
  14.   BEGTYPE
  15.  
  16.     This example shows we can create a simple data
  17.     base from EBL-Plus. This shows how File I/O and
  18.     SEEK() functions work in EBL-Plus.
  19. END
  20.   Color( normal)
  21.  
  22.         *
  23.         * Start by finding out how many records are already saved
  24.         *       in our simple database. For this example, our data
  25.         *       is saved in records of 80 characters each. The SEEK()
  26.         *       function here allows us to find out the number of
  27.         *       characters (bytes) in the file. In that function, 'R'
  28.         *       indicates the file we are presently Reading, and EOF
  29.         *       indicates to report the characters from the start of the
  30.         *       file to the End-Of-File (EOF).
  31.         *
  32. -Show
  33.   <%N                        |* open the test file
  34.   %I = SEEK( R,EOF)+79/80    |* How many 80 byte records?
  35.   Window( 15, 7, 65, 9, Single)
  36.   Type "Data base" %N "now contains" %I "records."
  37.   <                          |* close the file
  38.  
  39.         *
  40.         *    We will use COLORCHAR to "paint" each field where
  41.         *    a selection bar can be placed. For variety, we will
  42.         *    use different colors than before. Also note that we have
  43.         *    chosen the @ character to paint with because other characters
  44.         *    may be in our text that we will show.
  45.         *
  46. -Reqst
  47.   Color( Black on Black)
  48.   Window( 11, 12, 72, 18)
  49.   COLORCHAR '@' as color(Cyan on Blue)
  50.   Color( White on Blue)
  51.   Window( 10, 11, 70, 16)
  52.   TYPE
  53.   TYPE "     Select one:"
  54.   TYPE
  55.   TYPE "     @Add a record@   @Display a record@   @Exit@"
  56.   Color( Normal )
  57.  
  58.         *
  59.         * Now use the SELECT() function to show moving bar. Note that the
  60.         *    "field color" here must again match what was painted on the
  61.         *    screen above.
  62.         *
  63.         * When the SELECT() function ends, there are two important
  64.         *    pieces of information available.
  65.         *      1. The function itself will have a value of the key used
  66.         *         to make the selection. This is saved here in the
  67.         *         variable %K.
  68.         *      2. The %R return code variable will contain the "field
  69.         *         number" where the bar is positioned. For this example,
  70.         *         this is the easiest way to make a decision of what to do.
  71.         *
  72.     %K = SELECT( color(Cyan on Blue) )    |* Ask for selection
  73.  
  74.         *
  75.         * Now we will hold the resulting "field number" in %0 for convenience.
  76.         *
  77.     %0 = %R
  78.  
  79.         *
  80.         * Based on this information, we will choose which command to execute.
  81.         * Like BATDEMO3, we will use a computed-GOTO to decide which
  82.         *    choice to make. Remember from above, %0 now contains the field
  83.         *    number of the selection.
  84.         *
  85.   IF %K = ESC then EXIT                 |* exit if certain keys are pressed.
  86.   TYPE
  87.   TYPE
  88.   goto -Cmd.%0       |* goto routine to handle request
  89.  
  90.         *
  91.         * This section adds a record to the database. Adding information
  92.         * is started by opening a file for 'appending'. This is done so
  93.         * the existing contents is kept while new information is being
  94.         * written into the file. Although the data can be added at any
  95.         * record, we will always add it to the end of the database in this
  96.         * example.
  97.         *
  98.         * First, build a window to request the data to be saved.
  99.         *
  100. -Cmd.1
  101.   COLORCHAR '@' as color(white on Cyan)
  102.   Color( White on Blue)
  103.   Window( 11, 12, 71, 17)
  104.   TYPE
  105.   TYPE "Enter data to be saved:"
  106.   TYPE
  107.   TYPE "@                                                        @"
  108.   EDIT( color(white on cyan), Enter)
  109.   %A = strip(Field(1))
  110.   IF %A = "" then GOTO -reqst
  111.  
  112.         *
  113.         * Then put the data into the file.
  114.         *
  115.   >>%N               |* append to write (not create)
  116.   seek(W,(%I * 80))  |* seek to next available record
  117.   type left(%A,78)   |* write 78 chars max + CR/LF into rec
  118.   >                  |* close file
  119.   goto -show
  120.  
  121.         *
  122.         * This section displays a record's contents. First find out
  123.         * which record number is desired.
  124.         *
  125. -Cmd.2
  126.   COLORCHAR '@' as color(white on Cyan)
  127.   Color( White on Blue)
  128.   Window( 11, 12, 71, 17)
  129.   IF %I < 1 THEN
  130.     THEN TYPE "No records have been stored yet!"| TYPE
  131.     THEN TYPE 'Press <─┘ then select "Add a record";'| READ
  132.     THEN GOTO -reqst
  133.   TYPE "Record numbers 1 to" %I "are available."
  134.   TYPE "Which record to display? @@"
  135.   EDIT( color(white on cyan), Enter)
  136.   %A = strip(Field(1))
  137.   IF %A = "" then GOTO -reqst
  138.  
  139.         *
  140.         * Then open the file for reading, SEEK() to the requested
  141.         * record number, display it, and close the file.
  142.         *
  143.  <%N                      |* open to read file
  144.  seek( R, (%A - 1 * 80) ) |* go to requested record
  145.  read.parsed %0
  146.  <                        |* and close file
  147.  
  148.  color( Yellow on blue )
  149.  window( 12, 15, 72, 18, Single)
  150.  IF %0 = ^Z then %0 = "(nothing saved in record " & %A & "!)"
  151.  Type left(%0,55)         |* show window's portion of this record
  152.  Color( White on Blue)
  153.  TYPE "  (Press <─┘ to continue..);"
  154.  READ
  155.  Goto -Reqst
  156.  
  157. *
  158. * The third field in the main menu allows the user to Exit to DOS.
  159. *
  160. -Cmd.3  Exit
  161.  
  162.  
  163. *
  164. *       Errors that EBL-Plus finds will come here. In this case,
  165. *       we will create the database file if it is not found. Other
  166. *       errors will be unexpected and reported to the user before
  167. *       ending this application.
  168. *
  169. -on.error-                      |* errors come here
  170.  If %R = 33 then skip 1
  171.  If %R <> 32 then goto -err2    |* on file not found:
  172.     Type "Creating new database..."
  173.     >%N                         |* create empty file
  174.     >                           |*    (1st time only)
  175.     Resume (%L-1)               |* return to open error
  176. -err2
  177.  IF %R = 7 then Resume -Top     |* Reset menu if user entry error
  178.  Type "Unexpected error" %R "in line" %L
  179.  Exit
  180.