Dec 092017
 
A short, simple PAL Procedure which pops up a calculator pad and returns a total to a Field or Program Variable.
File CALCULTR.ZIP from The Programmer’s Corner in
Category Paradox DBMS
A short, simple PAL Procedure which pops up a calculator pad and returns a total to a Field or Program Variable.
File Name File Size Zip Size Zip Type
CALCULTR.DOC 4297 1897 deflated
CALCULTR.SC 1629 720 deflated

Download File CALCULTR.ZIP Here

Contents of the CALCULTR.DOC file


Calculator()




Calculator() is a PAL procedure for use with Paradox 3. It is designed to
fill a void in applications calling for totals to be inserted into fields or
assigned to program variables. It is totally generic and was designed to be
called from within a WAIT statement in DataEntry, Edit, or CoEdit program
modules or procedures. It can easily be adapted to function as a Toolkit
procedure called by a field level event. I have only used it in Version 3.01,
but there is no reason it should not function with Version 3.5 although it has
not been tested in that version.

Why use it? Maybe you won't want to. However I found the need to create
it while coding an invoicing application. The user needed to enter a series of
expenses into a single field. Each different vendor used different expense
categories, and they varied from bill to bill for the same vendor. The user got
tired of having to use a hand calculator to add the various expenses so that
only the total could be entered into the field being edited. I was requested to
program a user-friendly popup calculator which could be called up only when
needed. It seemed a simple solution, and it was.

As in most cases the job is best left to a procedure called from an
autoloading library. This procedure is extremely compact and simple. When
called, a window will pop up to the upper right of the canvas. The user simply
enters the amounts to be totaled. When the last figure or a "0" (zero) has been
input the total amount is returned to the calling script or procedure.

In the invoicing application I assigned a function key to the keypress exit
of a WAIT statement. When the key is pressed a test of the field type is
performed. If the field is a currency field the procedure is called, otherwise,
the program ignores the keypress and loops back into the WAIT. When the user
returns, the total is placed into the current field with the TYPEIN command. A
CR confirms the entry and moves the user to the next field in the form.

The procedure, as currently coded, allows for a total of twelve figures to
be added together. It can be easily modified to allow more or less by changing
the values in the FOR-ENDFOR statements and changing the rows at which the
borders display on the canvas. To correct mistakes the user simply needs to
enter a negative offset.

Although I haven't needed to use it in such a fashion it can probably be
adapted to run in interactive mode with the Miniscript option of the PAL menu.
To do so would require conditional testing for the current Sysmode() if you want
the total to be placed into a field currently being edited. If you don't
require field entry then the total can be displayed with the PAL MESSAGE
command.

Making this procedure has enabled me to reduce the number of unnecessary
fields in my table structures. The user for which I made it was so pleased that
I have incorporated it into other applications where it could be useful.

The accompanying script (CALCULTR.SC) contains the procedure and a little
routine at the end which demos the procedure by converting the RETVAL to a
string and printing it to the canvas. To incorporate the procedure simply
delete the last four lines, write it to a library and call it as you would any
other procedure. For Example:

WHILE True
WAIT RECORD
PROMPT "F8: Calculator " UNTIL "F8","Etc","Etc"
SWITCH
CASE RETVAL = "F8":
If FIELDTYPE() = "$" THEN
Calculate()
TYPEIN total.n
ELSE
BEEP
MESSAGE "Not a Currency Field"
SLEEP 1500
ENDIF
LOOP
CASE #1:
CASE #2:
ENDSWITCH
ENDWHILE

To see how it works simply play Calcultr.sc from within Paradox.

Feel free to use, modify, or trash this procedure as you see fit. I am
relatively new to PAL programming. Therefore, if you find a use for it please
drop me a line on the Programmer's Corner BBS with your comments or your
criticisms. That's how we learn!


Dan Statkus
Laurel, Maryland


 December 9, 2017  Add comments

Leave a Reply