home *** CD-ROM | disk | FTP | other *** search
HyperBook | 1991-01-29 | 6.9 KB | 99 lines |
- 2/* Adds the symbol that is the initiator's name to the text of the Display
- note.
- display = 'Display'()
- ckey = getname(initiator())
- if getvar(clear) then do
- if index('0123456789.()', ckey) > 0 then
- call cleartext(display)
- call setvar(clear,0)
- end
- call inserttext(display,ckey,-1)
- DoCalcKey
- "/* Calculator equals key */
- disp = 'Display'()
- expr = compress(readnotetext(disp,0,-1),'0a'X)
- if expr = '' then do
- call inserttext(disp, '0', 0)
- EXIT
- end
- signal on syntax
- interpret 'value =' expr
- signal off syntax
- call cleartext(disp)
- call inserttext(disp, value, 0)
- call interactive(0)
- pt = 'Paper tape'()
- it = appenditem(pt, expr, 1)
- call setactionmacro(it,'ToDisplay')
- it = appenditem(pt, compress(value,'0a'X), 2)
- call setactionmacro(it,'ToDisplay')
- call listscroll(it)
- call setvar(clear,1)
- syntax:
- call inform("Error")
- DoEqualsKey
- tx = getitemtext(initiator())
- n = index(tx, ';') - 1
- if n > 0 then
- tx = strip(left(tx, n))
- call inserttext('Display'(), tx, -1)
- ToDisplay
- /* Get a variable's value: val = getvar(name)
- variables are stored as items in an invisible list called "Vars"
- it = searchitems('vars'(),arg(1) '=')
- tx = getitemtext(it)
- return substr(tx, index(tx,'=') + 1)
- getvar(name)
- /* Set a variable: setvar(name, val)
- variables are stored as items in an invisible List called "Vars"
- vl = 'vars'()
- if arg() == 1 then
- if length(searchitems(vl,arg(1) '=')) > 0 then
- return 1
- else
- return 0
- it = searchitems(vl,arg(1) '=')
- if arg(2) = deletevar then do
- call delete(it)
- return 1
- end
- if length(it) > 0 then
- call setitemtext(it, arg(1) '=' || arg(2))
- call appenditem(vl, arg(1) '=' || arg(2), 1)
- return 1
- setvar(name,val)
- Button1
- call clearlist('Paper tape'())
- Clear paper tape
- "Frame"
- call cleartext('Display'())
- "Memory"
- gob='Display'(); text=readnotetext(ob,0,-1); call setclip('calculator_memory',left(text,length(text)-1))
- MEMORY
- "Recall"
- <call inserttext('Display'(),getclip('calculator_memory'),-1)
- RECALL
- Note1
- A Simple Calculator
- Operate the calculator by clicking on
- buttons with the mouse. Formulas are
- shown in the display, and are calculated
- when you press the "=" key.
- The MEMORY button stores the current
- display, which can be a number or entire
- formula. You can RECALL this number or
- formula at any time, appending it to the
- calculator display.
- The "paper tape" shows the formula and
- result of each calculation. You can click
- on any item in the paper tape to append
- that number or formula to the calculator
- display. "Clear paper tape" removes all
- items from the paper tape display.
- "Vars"
- CLEAR =1
- "Display"
- "Paper tape"
- "Calculator"
- diamond.font
-