Hi all,

Here's the start of a Calculator Program with the theory first.

TO MAKE A CALCULATOR

Part I

Ok how do we make a calcuklator? Well we start with the basic functions that are

needed.

1] Add

2] Subtract

3] Multiply

4] Divide

To make these functions we will need some data. We will obviously need the numbers

0123456789 and the symbols Add (+), Subtract (-), Multiply (*), Divide (\), Equals (=),clear

entry (c), clear all (a), Dot (.). So we will need to crate them as objects.

These will be objects that we click on with the mouse and by clicking on them we use

them. These objects need to be selected in the right sequence else we will create an error.

As humans if we selected the add symbol first and two numbers after we understand what it is

we wish to do. The computer can not do this. It needs defined and predictable actions to

respond to. So this means we have to have a set of rules that the program understands and

follows to arrive at the correct answer.

Before we come to the constructed actions of using these objects we need to define

the data types that will be used. An integer can be only minus 32,768 to 32,767. This size

may not be big enough for some operations. Also if a user enters a floating point figure (eg.

99.33) that will not work in an integer. We basically need two types LONG INTEGER(&) and

SINGLE(!).Somehow we need to detect if a user enters a DOT and make the appropriate type

selection based on that.

One way to allow any entry is to use strings$. We would build the string of numbers

entered until the user selects a symbol. Before we react to the symbol we scan the string$

for the dot. If we detect the dot then we have to use the FLOAT type. Next we would decode

the string into our first variable. So recapping the string gets converted into a FLOAT or a

SINGLE. The only other thing that need to be monitored is if the entered number is positive

or negative. This could potentially complicate it for us. The most obvious thing that i can

think of to differenciate between the symbol minus and negative is to use minus as an action

and then negative and positive as a condition. So in theory now we have to add 2 new symbols

to indicate positive and negative that only affects the sign of numbers.

Next is how the actions occur and get interpreted in the correct sequence. Normally a

user enters a number. This number is assumed to be positive unless he indicates its negative

with a different symbol selection. Next an operator is selected like addition. Next the user

enters a second number that may be positive or negative. Lastly the user selects a result

like equals.

Action1 + Action2 + Action3 + Action4 results in a calculation that appears in an output variable.