dbTalk Databases Forums  

Create an Calculator

comp.databases.progress comp.databases.progress


Discuss Create an Calculator in the comp.databases.progress forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Amberstar
 
Posts: n/a

Default Create an Calculator - 09-15-2003 , 04:01 AM







Hello,

i have to create a calculator with progress 9,

but i have no idea how to add firm worth

to the buttons and how to display the numbers and signs.





/********************** Define
Widgets***********************************/

define button eins label "1" size-chars 6 by 1.

define button zwei label "2" size-chars 6 by 1.

define button drei label "3" size-chars 6 by 1.

define button vier label "4" size-chars 6 by 1.

define button fuenf label "5" size-chars 6 by 1.

define button sechs label "6" size-chars 6 by 1.

define button sieben label "7" size-chars 6 by 1.

define button acht label "8" size-chars 6 by 1.

define button neun label "9" size-chars 6 by 1.

define button nnull label "0" size-chars 6 by 1.

define button plus label "+" size-chars 6 by 1.

define button minus label "-" size-chars 6 by 1.

define button mal label "*" size-chars 6 by 1.

define button geteilt label "/" size-chars 6 by 1.

define button komma label "," size-chars 6 by 1.

define rectangle rtc-border size-chars 50 by 13 no-fill.

define button btn-exit label "Exit".

define variable a as decimal.

define variable b as decimal.

define variable field1 as character .

define button rechne label "Berechne".





/*******************Define Frames********************************/



define frame frame1

rechne at row 13 column 32

eins at row 9 column 20

zwei at row 9 column 30

drei at row 9 column 40

vier at row 7 column 20

fuenf at row 7 column 30

sechs at row 7 column 40

sieben at row 5 column 20

acht at row 5 column 30

neun at row 5 column 40

nnull at row 11 column 20

plus at row 11 column 50

minus at row 9 column 50

mal at row 7 column 50

geteilt at row 5 column 50

komma at row 11 column 40

rtc-border at row 2 column 13

btn-exit at row 14 column 63

field1 at row 3 column 22 no-labels

with three-d center side-label title "Taschenrechner".





/*******************Define Triggers***************************/





ON 'choose':U OF eins



do:

field1 = string(1).

display field1 with frame frame1.

end.





ON 'choose':U OF zwei

DO:



field1 = string(2).

display field1 with frame frame1.

RETURN.

END.



/************Main Logic***************************************/





display rtc-border with frame frame1.

enable all with frame frame1.

wait-for choose of btn-exit.





I hope someone can help me.





greetz

Amber


--
Posted via http://dbforums.com

Reply With Quote
  #2  
Old   
Dmitry Lishafaev
 
Posts: n/a

Default Re: Create an Calculator - 09-16-2003 , 04:15 AM






"Amberstar" <member39548 (AT) dbforums (DOT) com> wrote

Quote:
Hello,
i have to create a calculator with progress 9,
but i have no idea how to add firm worth
to the buttons and how to display the numbers and signs.
with v8 :

press keys "2" "+" "2" "Berechne" "-" "5" "Berechne"

my code must be optimized

/********************** Define Widgets**********************/

define button eins label "1" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("1").
END.
define button zwei label "2" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("2").
END.
define button drei label "3" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("3").
END.
define button vier label "4" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("4").
END.
define button fuenf label "5" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("5").
END.
define button sechs label "6" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("6").
END.
define button sieben label "7" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("7").
END.
define button acht label "8" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("8").
END.
define button neun label "9" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("9").
END.
define button nnull label "0" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("0").
END.
define button plus label "+" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("+").
END.
define button minus label "-" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("-").
END.
define button mal label "*" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("*").
END.
define button geteilt label "/" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("/").
END.
define button komma label "," size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process (",").
END.

define rectangle rtc-border size-chars 50 by 13 no-fill.

define button btn-exit label "Exit".

define variable a as decimal.

define variable b as decimal.

define variable field1 as character .

define button rechne label "Berechne"
TRIGGERS:
ON CHOOSE RUN calc-process ("=").
END.


/*******************Define Frames********************************/



define frame frame1
rechne at row 13 column 32
eins at row 9 column 20
zwei at row 9 column 30
drei at row 9 column 40
vier at row 7 column 20
fuenf at row 7 column 30
sechs at row 7 column 40
sieben at row 5 column 20
acht at row 5 column 30
neun at row 5 column 40
nnull at row 11 column 20
plus at row 11 column 50
minus at row 9 column 50
mal at row 7 column 50
geteilt at row 5 column 50
komma at row 11 column 40
rtc-border at row 2 column 13
btn-exit at row 14 column 63
field1 at row 3 column 22 no-labels
with three-d center side-label title "Taschenrechner".

/************Main Logic***************************************/

DEF VAR t-operand AS DECIMAL.
DEF VAR t-optype AS CHAR.

display rtc-border with frame frame1.

enable all with frame frame1.


PROCEDURE calc-process:
DEF INPUT PARAMETER t-command AS CHAR NO-UNDO.

DO WITH FRAME frame1:

CASE t-command:
WHEN "1"
OR WHEN "2"
OR WHEN "3"
OR WHEN "4"
OR WHEN "5"
OR WHEN "6"
OR WHEN "7"
OR WHEN "8"
OR WHEN "9"
OR WHEN "0" THEN DO:
field1:SCREEN-VALUE = field1:SCREEN-VALUE + t-command.
END.

WHEN "+" THEN DO:
ASSIGN
t-optype = "+"
t-operand = DECIMAL(field1:SCREEN-VALUE)
field1:SCREEN-VALUE = "".
END.

WHEN "-" THEN DO:
ASSIGN
t-optype = "-"
t-operand = DECIMAL(field1:SCREEN-VALUE)
field1:SCREEN-VALUE = "".
END.


WHEN "=" THEN DO:
CASE t-optype:
WHEN "+" THEN DO:
t-operand = t-operand + DECIMAL(field1:SCREEN-VALUE).
END.
WHEN "-" THEN DO:
t-operand = t-operand - DECIMAL(field1:SCREEN-VALUE).
END.
END CASE.

ASSIGN
field1:SCREEN-VALUE = STRING(t-operand)


Reply With Quote
  #3  
Old   
Scott Auge
 
Posts: n/a

Default Re: Create an Calculator - 09-25-2003 , 01:45 PM



If you want to make your calculator algebraic, including formulae - see this

http://amduus.com/OpenSrc/SrcLib/EQN/2/

Examples of how to call it here:

http://amduus.com/OpenSrc/SrcLib/EQN/2/BatTestAlgCalc.p


Some test results:

Start Time: 15:03:59

Evaluating 42
42 = 42
Evaluating 2 + 4
2 + 4 = 6
Evaluating 2 + 4 * 3
2 + 4 * 3 = 14
Evaluating 2 + -4
2 + -4 = -2
Evaluating ( 2 + 4 ) * 3
( 2 + 4 ) * 3 = 18
Evaluating ( 2 + 4 ) * 3 * ( 7 + 3 )
( 2 + 4 ) * 3 * ( 7 + 3 ) = 180
Evaluating ( 2 + 4 * ( 3 + 3 ) ) * 3 * ( 7 + 3 )
( 2 + 4 * ( 3 + 3 ) ) * 3 * ( 7 + 3 ) = 780
Evaluating Power[ ( 3 + 4 ) ,2 ]
Power[ ( 3 + 4 ) ,2 ] = 49
Evaluating 2 * Power[ ( 3 + 4 ) ,2 ]
2 * Power[ ( 3 + 4 ) ,2 ] = 98
Evaluating Power[ ( 3 + 4 ) ,2 ] * 2
Power[ ( 3 + 4 ) ,2 ] * 2 = 98
Evaluating Power[ 7,2 ] * 3
Power[ 7,2 ] * 3 = 147
Evaluating Power[ 7,3 ]
Power[ 7,3 ] = 343
Evaluating Power[ Power[ 2,2 ] ,4 ]
Power[ Power[ 2,2 ] ,4 ] = 256
Evaluating ((3+4)*5)/2
((3+4)*5)/2 = 17.5
Evaluating (2*(2+4))
(2*(2+4)) = 12

Checking IF [ ] Function

Evaluating if[ 1 > 2,1,0 ]
if[ 1 > 2,1,0 ] = 0
Evaluating if[ 1 < 2,1,0 ]
if[ 1 < 2,1,0 ] = 1
Evaluating if[ 1 = 2,1,0 ]
if[ 1 = 2,1,0 ] = 0
Evaluating if[ 1 <= 2,1,0 ]
if[ 1 <= 2,1,0 ] = 1
Evaluating if[ 1 >= 2,1,0 ]
if[ 1 >= 2,1,0 ] = 0
Evaluating if[ 1 != 2,1,0 ]
if[ 1 != 2,1,0 ] = 1

More complicated ifs

Evaluating if[ (1+1-1) != 2,1,0 ]
if[ (1+1-1) != 2,1,0 ] = 1
Evaluating if[ 1 != (1+1),1,0 ]
if[ 1 != (1+1),1,0 ] = 1
Evaluating if[ 1 != 2, (2 - 1) ,0 ]
if[ 1 != 2, (2 - 1) ,0 ] = 1
Evaluating if[ 1 != 2, (2 + 1) ,0 ]
if[ 1 != 2, (2 + 1) ,0 ] = 3
Evaluating if[ 1 != 2, 1,0 ]
if[ 1 != 2, 1,0 ] = 1

Testing Min

Evaluating min[ 2,1 ]
min[ 2,1 ] = 1
Evaluating min[ Power[ 7,(1 + 1) ] ,1 ]
min[ Power[ 7,(1 + 1) ] ,1 ] = 1

Testing Max

Evaluating max[ 2,1 ]
max[ 2,1 ] = 2
Evaluating max[ Power[ 7,(1 + 1) ] ,1 ]
max[ Power[ 7,(1 + 1) ] ,1 ] = 49

Messing with formulae

Adding @AttrPastMort = 3
Adding @AttrPastCC = 20000
Adding @AttrPastMisc = 3000
Adding @Grade = @GradeMort + @GradeCard + @GradeMisc
Adding @GradeMort = if[ @AttrPastMort > 2, 1, 0 ]
Adding @GradeCard = if[ @AttrPastCC > 30000, 0, 1 ]
Adding @GradeMisc = if[ @AttrPastMisc > (2000 + 3000),1,0 ]

Formula List

@AttrPastCC = 20000
@AttrPastMisc = 3000
@AttrPastMort = 3
@Grade = @GradeMort + @GradeCard + @GradeMisc
@GradeCard = if[ @AttrPastCC > 30000, 0, 1 ]
@GradeMisc = if[ @AttrPastMisc > (2000 + 3000),1,0 ]
@GradeMort = if[ @AttrPastMort > 2, 1, 0 ]

Computing Formulae

Evaluating @GradeMisc
@GradeMisc = 0
Evaluating @GradeMisc + 3
@GradeMisc + 3 = 3
Evaluating @GradeCard
@GradeCard = 1
Evaluating @GradeMort
@GradeMort = 1
Evaluating @Grade
@Grade = 2

Ending Time: 15:03:59
Duration: 0


"Dmitry Lishafaev" <dmi (AT) viwanet (DOT) ru> wrote

Quote:
"Amberstar" <member39548 (AT) dbforums (DOT) com> wrote in message
news:3370349.1063616481 (AT) dbforums (DOT) com...

Hello,
i have to create a calculator with progress 9,
but i have no idea how to add firm worth
to the buttons and how to display the numbers and signs.

with v8 :

press keys "2" "+" "2" "Berechne" "-" "5" "Berechne"

my code must be optimized

/********************** Define Widgets**********************/

define button eins label "1" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("1").
END.
define button zwei label "2" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("2").
END.
define button drei label "3" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("3").
END.
define button vier label "4" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("4").
END.
define button fuenf label "5" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("5").
END.
define button sechs label "6" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("6").
END.
define button sieben label "7" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("7").
END.
define button acht label "8" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("8").
END.
define button neun label "9" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("9").
END.
define button nnull label "0" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("0").
END.
define button plus label "+" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("+").
END.
define button minus label "-" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("-").
END.
define button mal label "*" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("*").
END.
define button geteilt label "/" size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process ("/").
END.
define button komma label "," size-chars 6 by 1
TRIGGERS:
ON CHOOSE RUN calc-process (",").
END.

define rectangle rtc-border size-chars 50 by 13 no-fill.

define button btn-exit label "Exit".

define variable a as decimal.

define variable b as decimal.

define variable field1 as character .

define button rechne label "Berechne"
TRIGGERS:
ON CHOOSE RUN calc-process ("=").
END.


/*******************Define Frames********************************/



define frame frame1
rechne at row 13 column 32
eins at row 9 column 20
zwei at row 9 column 30
drei at row 9 column 40
vier at row 7 column 20
fuenf at row 7 column 30
sechs at row 7 column 40
sieben at row 5 column 20
acht at row 5 column 30
neun at row 5 column 40
nnull at row 11 column 20
plus at row 11 column 50
minus at row 9 column 50
mal at row 7 column 50
geteilt at row 5 column 50
komma at row 11 column 40
rtc-border at row 2 column 13
btn-exit at row 14 column 63
field1 at row 3 column 22 no-labels
with three-d center side-label title "Taschenrechner".

/************Main Logic***************************************/

DEF VAR t-operand AS DECIMAL.
DEF VAR t-optype AS CHAR.

display rtc-border with frame frame1.

enable all with frame frame1.


PROCEDURE calc-process:
DEF INPUT PARAMETER t-command AS CHAR NO-UNDO.

DO WITH FRAME frame1:

CASE t-command:
WHEN "1"
OR WHEN "2"
OR WHEN "3"
OR WHEN "4"
OR WHEN "5"
OR WHEN "6"
OR WHEN "7"
OR WHEN "8"
OR WHEN "9"
OR WHEN "0" THEN DO:
field1:SCREEN-VALUE = field1:SCREEN-VALUE + t-command.
END.

WHEN "+" THEN DO:
ASSIGN
t-optype = "+"
t-operand = DECIMAL(field1:SCREEN-VALUE)
field1:SCREEN-VALUE = "".
END.

WHEN "-" THEN DO:
ASSIGN
t-optype = "-"
t-operand = DECIMAL(field1:SCREEN-VALUE)
field1:SCREEN-VALUE = "".
END.


WHEN "=" THEN DO:
CASE t-optype:
WHEN "+" THEN DO:
t-operand = t-operand + DECIMAL(field1:SCREEN-VALUE).
END.
WHEN "-" THEN DO:
t-operand = t-operand - DECIMAL(field1:SCREEN-VALUE).
END.
END CASE.

ASSIGN
field1:SCREEN-VALUE = STRING(t-operand)
.
END. /* = */

END CASE.



END.

END PROCEDURE.

wait-for choose of btn-exit.

/dmi

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.