home *** CD-ROM | disk | FTP | other *** search
/ norge.freeshell.org (192.94.73.8) / 192.94.73.8.tar / 192.94.73.8 / pub / computers / cpm / alphatronic / TP_301A.ZIP / mc.pas < prev    next >
Pascal/Delphi Source File  |  1985-01-01  |  7KB  |  160 lines

  1. program MicroCalc;
  2. {
  3.     MICROCALC DEMONSTRATION PROGRAM  Version 1.00A
  4.  
  5.   This program is Copyrighted by Borland International, Inc.
  6.   1983, 1984, 1985 and is hereby donated to the public domain for
  7.   non-commercial use only.  Dot commands are for the program
  8.   lister:   LISTT.PAS  (available with  our TURBO TUTOR):
  9.  
  10.       .PA, .CP20, etc...
  11.  
  12.   INSTRUCTIONS
  13.     1.  Compile this program using the TURBO.COM compiler.
  14.         a.  Use the O command from the main menu to select Options.
  15.         b.  Select the C option to generate a .COM file.
  16.         c.  Select the Q option to Quit the Options menu.
  17.         d.  Select the M option to specify the Main file
  18.         e.  Type "MC" and hit <RETURN>
  19.         f.  Type C to compile the program to disk
  20.         g.  Type R to run the program
  21.  
  22.     2.  Exit the program by typing: /Q
  23. }
  24.  
  25. {$R-,U-,V-,X-,A+,C-}
  26.  
  27.  
  28. const
  29.   FXMax: Char  = 'G';  { Maximum number of columns                   }
  30.   FYMax        = 21;   { Maximum number of lines                     }
  31.  
  32. type
  33.   Anystring   = string[255];
  34.   ScreenIndex = 'A'..'G';
  35.   Attributes  = (Constant,Formula,Txt,OverWritten,Locked,Calculated);
  36.  
  37. { The spreadsheet is made out of Cells every Cell is defined as      }
  38. { the following record:                                              }
  39.  
  40.   CellRec    = record
  41.     CellStatus: set of Attributes; { Status of cell (see type def.)  }
  42.     Contents:   String[70];        { Contains a formula or some text }
  43.     Value:      Real;              { Last calculated cell value      }
  44.     DEC,FW:     0..20;             { Decimals and Cell Whith         }
  45.   end;
  46.  
  47.   Cells      =  array[ScreenIndex,1..FYMax] of CellRec;
  48.  
  49. const
  50.   XPOS: array[ScreenIndex] of integer = (3,14,25,36,47,58,68);
  51.  
  52. var
  53.   Screen:        Cells;             { Definition of the spread sheet }
  54.   FX:            ScreenIndex;       { Culumn of current cell         }
  55.   FY:            Integer;           { Line of current cell           }
  56.   Ch:            Char;              { Last read character            }
  57.   MCFile:        file of CellRec;   { File to store sheets in        }
  58.   AutoCalc:      boolean;           { Recalculate after each entry?  }
  59.  
  60.  
  61. { The following include files contain procedures used in MicroCalc.  }
  62. { In the following source code there is a reference after each       }
  63. { procedure call indicating in which module the procedure is located.}
  64.  
  65. { If you want a printer listing of the following modules then you    }
  66. { must let the include directives start in column one and then use   }
  67. { the TLIST program to generate a listing.                           }
  68.  
  69.  {$I MC-MOD00.INC        Miscelaneous procedures                     }
  70.  {$I MC-MOD01.INC        Initialization procedures                   }
  71.  {$I MC-MOD02.INC        Commands to move between fields             }
  72.  {$I MC-MOD03.INC        Commands to Load,Save,Print                 }
  73.  {$I MC-MOD04.INC        Evaluating an expression in a cell          }
  74.  {$I MC-MOD05.INC        Reading a cell definition and Format command}
  75.  
  76.  
  77. {.PA}
  78. {*********************************************************************}
  79. {*                START OF MAIN PROGRAM PROCEDURES                   *}
  80. {*********************************************************************}
  81.  
  82.  
  83. { Procedure Commands is activated from the main loop in this program }
  84. { when the user type a semicolon. Commands then activates a procedure}
  85. { which will execute the command. These procedures are located in the}
  86. { above modules.                                                     }
  87. { For easy reference the source code module number is shown in a     }
  88. { comment on the right following the procedure call.                 }
  89.  
  90. procedure Commands;
  91. begin
  92.   GotoXY(1,24);
  93.   HighVideo;
  94.   Write('/ restore, Quit, Load, Save, Recalculate, Print,  Format, AutoCalc, Help ');
  95.   Read(Kbd,Ch);
  96.   Ch:=UpCase(Ch);
  97.   case Ch of                                             { In module }
  98.     'Q': Halt;
  99.     'F': Format;                                               {  04 }
  100.     'S': Save;                                                 {  03 }
  101.     'L': Load;                                                 {  03 }
  102.     'H': Help;                                                 {  03 }
  103.     'R': Recalculate;                                          {  05 }
  104.     'A': Auto;                                                 {  00 }
  105.     '/': Update;                                               {  01 }
  106.     'C': Clear;                                                {  01 }
  107.     'P': Print;                                                {  03 }
  108.   end;
  109.   Grid;                                                        {  01 }
  110.   GotoCell(FX,FY);                                             {  02 }
  111. end;
  112.  
  113. { Procedure Hello says hello and activates the help procedure if the }
  114. { user presses anything but Return                                   }
  115.  
  116. procedure Wellcome;
  117.  
  118.   procedure Center(S: AnyString);
  119.   var I: integer;
  120.   begin
  121.     for I:=1 to (80-Length(S)) div 2 do Write(' ');
  122.     writeln(S);
  123.   end;
  124.  
  125. begin { procedure Wellcome }
  126.   ClrScr; GotoXY(1,9);
  127.   Center('Welcome to MicroCalc.  A Turbo demonstation program');
  128.   Center('Copyright 1983 by Borland International Inc. ');
  129.   Center('Press any key for help or <RETURN> to start');
  130.   GotoXY(40,12);
  131.   Read(Kbd,Ch);
  132.   if Ch<>^M then Help;
  133. end;
  134.  
  135. {.PA}
  136. {*********************************************************************}
  137. {*          THIS IS WHERE THE PROGRAM STARTS EXECUTING               *}
  138. {*********************************************************************}
  139.  
  140. begin
  141.   Init;                                                        {  01 }
  142.   Wellcome;
  143.   ClrScr; Grid;                                                {  01 }
  144.   GotoCell(FX,FY);
  145.   repeat
  146.     Read(Kbd,Ch);
  147.     case Ch of
  148.       ^E:       MoveUp;                                        {  02 }
  149.       ^X,^J:    MoveDown;                                      {  02 }
  150.       ^D,^M,^F: MoveRight;                                     {  02 }
  151.       ^S,^A:    MoveLeft;                                      {  02 }
  152.       '/':      Commands;
  153.       ^[:       GetCell(FX,FY);                                {  04 }
  154.     else
  155.       if Ch in [' '..'~'] then
  156.       GetCell(FX,FY);                                          {  04 }
  157.     end;
  158.   until true=false;          { (program stops in procedure Commands) }
  159. end.
  160.