-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCALC.PAS
More file actions
183 lines (167 loc) · 10.8 KB
/
Copy pathCALC.PAS
File metadata and controls
183 lines (167 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
{*************************************************************************}
{ }
{ MicroCalc Spread Sheet }
{ Version 2.0 }
{ }
{ This program is hereby donated to the public domain for non-commercial }
{ use only. }
{ }
{ The MicrCalc program has been included on our TURBO PASCAL disk for two}
{ reasons. One, as a sample program for you to study, modify, etc. and }
{ also as a usefull program that will meet the spread sheet needs of the }
{ majority of TURBO PASCAL users. }
{ }
{ Many users have expressed the neeed for more sample programs written in}
{ TURBO PASCAL for them to look at and study. While most of us will never}
{ take full advantage of the powers offered by the average spread sheet }
{ on the market these days. Thus, MicroCalc serves two usefull perposes. }
{ }
{ INSTRUCTIONS : }
{ 1. Compile this program using the TURBO.COM compiler. }
{ A. Type 'TURBO' <CARRIAGE RETURN> at the operating system command }
{ line. }
{ B. Type 'Y' to Include error messages }
{ C. Type 'W' for Workfile }
{ D. Type 'CALC' for Workfile name }
{ E. Type 'R' for run }
{ 2. If you receive a Compiler Overflow message - Error # 99 then }
{ A. follow steps A through D above }
{ B. Type 'O' for compiler Options }
{ C. Type 'C' for .COM file }
{ D. Type 'Q' to Quit compiler Options }
{ E. Type 'C' for Compile }
{ F. Type 'Q' to Quit TURBO PASCAL }
{ G. Type 'CALC' at the operating system command line. }
{ }
{*************************************************************************}
{*************************************************************************}
{ }
{ Main MicroCalc Module }
{ Last Modified 7-22-85 }
{ }
{ The MicroCalc program has been divided into several modules. Each }
{ module contains related routines, thus enabling the programmer to }
{ follow the code more easily. Following is a description of each of the }
{ modules : }
{ }
{ Module Name : Main MicroCalc Module }
{ FileName : CALC.PAS }
{ Contents : }
{ 1. Global Variable Declarations }
{ 2. Procedure Commands (* called when user types "/" *) }
{ 3. Main program body }
{ }
{ Module Name : MicroCalc Module 000 }
{ FileName : CALC.INC }
{ Contents : }
{ 1. Miscellaneous routines }
{ }
{ Module Name : MicroCalc Module 001 }
{ FileName : CALC.INC }
{ Contents : }
{ 1. Procedure Grid - Displays the spread sheet on the }
{ screen }
{ 2. Procedure Init - Initializes all cells in the spread }
{ sheet }
{ 3. Procedure Clear - clears the current spread sheet }
{ }
{ Module Name : MicroCalc Module 002 }
{ FileName : CALC.INC }
{ Contents : }
{ 1. Procedure DisplayType - indicates the type and }
{ contents of a cell }
{ 2. Cursor movement procedures - called when user presses }
{ the arrow keys }
{ }
{ Module Name : MicroCalc Module 003 }
{ FileName : CALC.INC }
{ Contents : }
{ 1. Procedures Load, Save and Print - Load a new spread }
{ sheet, Save the current spread sheet, and print the }
{ current spread sheet }
{ 2. Procedure Help - on line help system }
{ Special Note : If you are operating under MS/PC-DOS, you can take }
{ full advantage of DOS's filename ficilities by mod- }
{ -ifying line 56 (* remove comments *) }
{ }
{ Module Name : MicroCalc Module 004 }
{ FileName : CALC.PAS }
{ Contents : }
{ 1. Procedure Evaluate - Evaluates a string passed to it }
{ 2. Procedure ReCalculate - Recalculates each cell in the }
{ spread sheet }
{ }
{ Module Name : MicroCalc Module 005 }
{ File Name : CALC.PAS }
{ Contents : }
{ 1. Procedure GetCell - I/O routine that gets cell's }
{ contents from the user. }
{ 2. Procedure Format - allows user to format a range of }
{ cells. }
{ }
{*************************************************************************}
Program MicroCalc;
const
FXMax : Char = 'G'; { Maximum number of columns in spread sheet }
FYMax = 21; { Maximum number of lines in spread sheet }
EofLine = ^M;
Numbers : set of Char = ['0'..'9'];
type
Anystring = string[70];
String3 = string[3];
ColumnName = 'A'..'G';
Attributes = (Constant,Formula,Txt,OverWritten,Locked,Calculated);
SetOfAttri = Set of Attributes;
{ The spreadsheet is made out of cells. Each cell is defined as the }
{ following record: }
CellRec = record
CellStatus : set of Attributes; { Status of cell (see type def.) }
Contents : String[70]; { Contains a formula or some text }
Value : Real; { Last calculated cell value }
DEC, FW : 0..20; { Decimals and Cell Width }
end;
Cells = array['A'..'G',1..FYMax] of CellRec;
const
{Initialize the array XPOS to hold the left most position of each column.}
XPOS : array['A'..'G'] of Integer = (3,14,25,36,47,58,68);
var
Sheet : Cells; { Definition of the spread sheet }
FX : ColumnName; { Culumn of current cell }
FY : Integer; { Line of current cell }
Ch : Char; { Last read Character }
MCFile : file of CellRec; { File to store sheets in }
AutoCalc,
Form : boolean; { Recalculate after each entry? }
FileName : AnyString;
Line : string[100];
{$I CALC.INC}
{*************************************************************************}
{ THIS IS WHERE THE PROGRAM STARTS EXECUTING }
{*************************************************************************}
begin
Init; { 001 }
Welcome; { 001 }
ClrScr;
Grid; { 001 }
GotoCell(FX,FY); { 002 }
repeat
Read(KBD,Ch); { Read KeyBoard without echoing to screen }
if KeyPressed then { Check for remaining characters in buffer, }
begin { if a character remains then a key with an }
Read(KBD,Ch); { extended scan code was pressed. Thus, read }
IBMCh(Ch); { the second character. }
end;
case Ch of {Based on the value of Ch execute the appropriate routine. }
^E : MoveUp; { 002 }
^X, ^J : MoveDown; { 002 }
^D, ^M, ^F : MoveRight; { 002 }
^S, ^A : MoveLeft; { 002 }
'/' : Commands;
^[ : GetCell(FX,FY); { 004 }
else
if Ch in [' '..'~'] then
GetCell(FX,FY); { 005 }
end;
until True = False; { (program stops in procedure Commands) }
end.