This article is reprinted from the April 1990 edition of
TechNotes/Framework III.  Due to the limitations of this media,
certain graphic elements such as screen shots, illustrations and some
tables have been omitted.  Where possible, reference to such items has
been deleted.  As a result, continuity may be compromised.  

TechNotes is a monthly publication from the Ashton-Tate Software
Support Center.  For subscription information, call 800-545-9364.

Armchair FRED-Part One
Kent Irwin

You say you just don't understand FRED?  You've worked your way
through the Tutorial and, sure, everything is real neat and spiffy in
Framework.  But you don't understand how to tie it all together? 
You'd like to customize Framework to your own daily tasks, but just
can't figure out how?  You've heard people talk about "programs" in
Framework, and don't know what they mean? Take heart, because this new
series will take you on a tour of Framework through the eyes of FRED,
and all without leaving your living room armchair.  Together we will
explore the simplest applications of formulas in spreadsheets; proper
use of the ominous-sounding macros; how, where, why, and what to do
with programs; linking different types of frames; and other topics
which will interest Framework users of all experience levels. For
obvious reasons, it will be assumed from the beginning that you have
completed the Using Framework III manual, and are relatively familiar
with the Framework system, including the use of the special function
keys (MOVE, COPY, EDIT, IN, etc.), the pull-down menus, the basic
frame types, and loading and saving files.  So, with the basics behind
you, and FRED before you, pull up your armchair and we'll dive right
in.

"All the world is frames," Shakespeare once said (or something like
that), and surely he was talking about Framework.  The frame is the
basic unit of operation throughout Framework in the same way that
sheets of paper could be considered the basic units of your office
desktop.  In fact, I like to think of frames in just that way; as
sheets of paper.  Think about it: when you DRAG a frame, it's like
pushing a sheet across your desk.  And when you Create a new frame,
you're pulling out a new sheet of paper and setting it on your desk to
start a new document.  The formula portion of a frame, then, would be
the back side of the paper. When you press F2 (FORMULA EDIT), you are
"bending back" the top of the page to peek at just the first line on
the back of your sheet.  Likewise, when you press F2 (FORMULA EDIT)
and then F9 (ZOOM), it's like flipping the whole sheet over so you can
view the whole backside.  The front of a frame is called the
"contents," and the backside is called the "formula" or "formula
space." Hopefully, you have had a chance to work with the contents
portion of the different types of frames, so we will concentrate on
how to use the formula space to make Framework sit up and take notice
of your special needs.
The first place anyone thinks of using the formulas of FRED is in a
spreadsheet, naturally, because FRED is very similar to the formulas
used in conventional spreadsheets, and because the goal of
spreadsheets in general is to make calculations easy.  But Framework
allows any frame to have a formula behind it.  In a way, you can think
of frames as big spreadsheet cells, or think of each cell as being a
frame.  This means that a FRED program of up to 64,000 characters can
be stored in any of those formula spaces.  The only practical
limitation on this is that the formula space behind a database frame
is special, and is used to "filter" the records to a select group (see
page 4-29 of the Using Framework III Manual).  Whereas that formula
could be very large, it is a good idea to keep important control
programs in some other type of frame.

Getting Started

What is a program anyway?  In FRED, a program is a collection of one
or more functions, separated by commas, which are evaluated one at a
time to produce a desired result.  As our first example, we will take
the simplest case: a single function behind an Empty/Word Frame. 
Start with an empty desktop and Create an Empty/Word Frame.  Title it
"Memory".  Now press F2 (FORMULA EDIT), and you see the cursor on the
edit line, and a prompt at the bottom of the screen that says,
"Formula/number editing; RETURN finishes."  Type @memavail and press
.  Notice that the frame contents now has a number in it.  This is
the result of our simple one-function program.  The function you typed
in, @memavail, returns the number of bytes of memory remaining on your
desktop.

This is a good time to discuss an important concept in FRED
programming: every function returns a value.  Even if the function
does not perform a calculation it still returns some kind of value. 
What good is that, you ask?  Well, it means that any function can be
used to return a value to some other function, allowing a programmer
to very easily test the result from any function he has used.

Now let's consider how to improve our simplistic example.  It might be
nice to have the result (value) of the program appear on the prompt
line at the bottom of the screen, formatted with commas, and maybe
even a friendly message like "You have 23,456 bytes remaining on the
desktop".  The Alt-F5 macro in the Framework III Library cabinet
already does that, but humor me and pretend that it's a novel idea. 
The program is listed below:

; Show the amount of memory remaining. 
@eraseprompt,
@prompt( "You have " & @business( @memavail,0 ) &
        " bytes remaining on the desktop." )

To enter the program, highlight the same frame you used before,
Memory, and press F2 (FORMULA EDIT) and F9 (ZOOM) to work with the
whole formula space (the backside of the frame, remember?), then
Ctrl-PgDn and Del to delete the old formula.  Type in the new program,
and press Esc when done.  Any time you highlight the frame border and
press F5 to recalculate, you will see a message at the bottom of the
screen displaying how much memory you have; and it doesn't matter if
the frame is open or closed.  The first thing the program does is
erase the prompt line (always a good practice), then it displays a
prompt.  Notice that there are only two main functions to the program,
@eraseprompt and @prompt, so there must be a comma between the
functions, but not after the last one.  All the @prompt function does
is print a string on the prompt line, but before it can do that with
our prompt, the @business and @memavail functions have to be
evaluated.  FRED starts evaluating a function at the innermost
parentheses so that it can pass the result to the surrounding
function.  In this case, FRED begins with @memavail, takes the result
(a number) and uses it in @business, which converts the number to a
string and formats it with commas.  The ampersand (&) characters you
see are used to stick strings together.  For instance, the string "You
have " has the string from @business concatenated to it, and then "
bytes remaining on the desktop" is concatenated to the end of that. 
This whole string is then passed to @prompt to be displayed.  Pretty
simple, isn't it?

Storing Your Results

Just for fun, let's suppose that you wanted to save that memory
remaining result somewhere so you could use it later.  There's a lot
of places that could hold that value for you, so we'll try several of
them to demonstrate various storage techniques.  You still have the
frame named Memory, right?  Okay, now create a new frame and label it
"Storage".  Go ahead and press F3 (DRAG) and F4 (SIZE) to drag and
size it so that it is in one corner of the desk, and shows about one
row and ten columns in the contents.  This is not crucial, but does
make it convenient to watch what is going on with that frame.  Now,
edit the formula in Memory to look like the code below:

; Show the amount of memory remaining. 
@eraseprompt, 
Storage := @memavail, 
@prompt( "You have " & @business( Storage, 0) &
        " bytes remaining on the desktop." )

The only change in the result you will see is a slight decrease in the
value of memory available because of the additional line we added to
the program.  Now the Storage frame shows that value in its contents. 
What we have done here is use a frame as a variable.  You can do the
same thing with a spreadsheet cell, that is, put the value of memory
remaining into a particular cell.  First, delete the Storage frame,
then create a spreadsheet frame, label it Storage, and edit the
formula of Memory to change each occurrence of the word "storage" to
"Storage.A1." Recalculating  the Memory frame now will put the result
into cell A1 of the spreadsheet. The important thing to note here is
that any frame or cell can be used just like a program variable.

Great!  We're moving along just fine.  There's one more way to use
variables that I want to tell you about, and then you can get back to
all those important programs you're writing.  First, delete that
Storage spreadsheet, and then edit the formula in Memory to look like 
the code below:

; Show memory remaining. 
@local( Storage ), 
@eraseprompt, 
Storage := @memavail, 
@prompt( "You have " & @business( Storage,0 ) &
        " bytes remaining on the desktop." )

You have just been introduced to local variables. Think of them as
"pigeon holes", or mail slots.  Each local variable must be declared
in the @local statement before it is used, and each variable can hold
one value.  That value can, of course, be a number or a character
string.  The real difference between using a local variable and using
a frame is that the local variable exists only in the program that
declared it and will disappear when the program is finished, whereas
the frame variable is independent and can be used by any number of
programs as well as having all the normal frame capabilities (that is
sizing, dragging, hiding, etc.).  Local variables are used for
temporary storage of values, like if you wanted to set aside an
intermediate result while you performed some other calculations, and
then wanted to retrieve the first value to use again.  The best
analogy for this is a desktop calculator.  Surely you've seen a
calculator that has a memory function (like M+,M-,MR)?  Well, turning
on the calculator is like running a FRED program, storing something to
the calculator's memory is like storing to a FRED local variable,
writing something on a piece of paper next to the calculator is like
storing to a frame variable, and the end of a FRED program is like
turning off the calculator because both the calculator's memory and
FRED's local variables would be lost.

That's about it for this session, so go try out some of these
concepts, and please, please, please experiment!  There is no better
way to learn programming than hands-on experience.  Be sure to examine
the FRED Framework III manual for details about FRED functions.  Look
for Part 2 of Armchair FRED in the next issue of TechNotes. 

