| CREATING THE abcDB CALCULATOR APPLICATION |
Note: The following tutorial application can be downloaded
here, although we highly recommend that you create this
application manually using the step-by-step methods shown
here:
This application will
really drive home the ability of abcDB to create powerful working PROGRAMS. In the next few minutes, we’re going to
develop a full working calculator using some more abcDB
‘magic’.
So, let’s get started!
|
First, let's create a new database. Call it Calculator. Now that we've got an 'empty'
database, let's get started. Let's create a new form. When prompted, call this form
CALCULATOR. Do not base it on any
table. Add the following controls: CONTROL
TYPE
Caption
TAG TEXTBOX
DISPLAY LABEL
Root
lblRoot LABEL
1/x
lblFraction LABEL
M+
lblMemPlus LABEL
<-
lblBackspace LABEL
%
lblPercent LABEL
MC
lblMemClear LABEL
MR
lblMemRecall LABEL
Clear
lblClear LABEL
1
lblOne LABEL
2
lblTwo LABEL
3
lblThree LABEL
4
lblFour LABEL
5
lblFive LABEL
6
lblSix LABEL
7
lblSeven LABEL
8
lblEight LABEL
9
lblNine LABEL
0
lblZero LABEL
.
lblDecimal LABEL
=
lblEquals LABEL
+
lblPlus LABEL
-
lblMinus LABEL
*
lblMultiply LABEL
/
lblDivide |
![]() |
|
Now, let’s add the code necessary
to make our ‘keys’ work.
We’ll program the 0-9 keys, and the + - * / .
keys. CONTROL
Code to place in ON CLICK
event. lblOne
SETVALUE(~DISPLAY~//~DISPLAY~“1”) lblTwo
SETVALUE(~DISPLAY~//~DISPLAY~“2”) lblThree
SETVALUE(~DISPLAY~//~DISPLAY~“3”) lblFour
SETVALUE(~DISPLAY~//~DISPLAY~“4”) lblFive
SETVALUE(~DISPLAY~//~DISPLAY~“5”) lblSix
SETVALUE(~DISPLAY~//~DISPLAY~“6”) lblSeven
SETVALUE(~DISPLAY~//~DISPLAY~“7”) lblEight
SETVALUE(~DISPLAY~//~DISPLAY~“8”) lblNine
SETVALUE(~DISPLAY~//~DISPLAY~“9”) lblZero
SETVALUE(~DISPLAY~//~DISPLAY~“0”) lblPlus
SETVALUE(~DISPLAY~//~DISPLAY~“+”) lblMinus
SETVALUE(~DISPLAY~//~DISPLAY~“-”) lblMultiply
SETVALUE(~DISPLAY~//~DISPLAY~“*”) lblDivide
SETVALUE(~DISPLAY~//~DISPLAY~“/”) lblDecimal
SETVALUE(~DISPLAY~//~DISPLAY~“.”) If we wanted to get REAL fancy, we could play a different sound when each key is tapped by adding something like this in each keys ONCLICK event: PLAYSOUND(“/My
Documents/MySound.wav”//1) But
I’ll leave that up to you.
For now, let’s SAVE our form (use the name CALC) and we’ll test it out. |
![]() |
|
Cool! It works! We can enter numbers and
calculations.
Unfortunately, pressing the “=”
button doesn’t do anything, so our calculator is still pretty much
useless! So let’s fix this
now. In the ON CLICK event of the
lblEquals control, enter the following code: SETVALUE(~DISPLAY~//eval(~DISPLAY~)) This
will evaluate the currently displayed expression and store the result in
our DISPLAY textbox. Try it
out and you’ll see that it works. But for
now, let’s get our other function keys working on our
calculator… |
|
Enter the
following code in the controls specified: CONTROL
Code to place in ON CLICK
event. lblRoot
SETMEM(ROOT//SQR(~DISPLAY~))
SETVALUE(~DISPLAY~//<!ROOT!>) lblPercent
SETMEM(PERCENT//~DISPLAY~/100)
SETVALUE(~DISPLAY~//<!PERCENT!>) lblFraction
SETMEM(FRACTION//1/~DISPLAY~)
SETVALUE(~DISPLAY~//<!FRACTION!>) lblMemClear
SETMEM(MEMORY//0) lblMemAdd
SETMEM(MEMORY//<!MEMORY!>
+ ~DISPLAY~) lblMemRecall
SETVALUE(~DISPLAY~//<!MEMORY!>) lblBackspace SETMEM(LENGTH//LEN(~DISPLAY~))
lblClear
SETVALUE(~DISPLAY~//) Once you’ve saved these changes and run the program, you should be able to use our calculator to perform calculations. This screen shot shows the results of entering 19.89 * 5:
What else could we do to make it better?
Well, you may want to set the NAVIGATIONMENU property of the form to
NO. That we we won't see the unnecessary menu at the top of the
screen. Again, I'll leave that up to
you. In any case, you can see from this little exercise some more evidence that abcDB Database truly is a powerful ‘mobile’ programming tool! |