# Rexx Calculator

Author Message
Susanta

Active User

Joined: 17 Nov 2009
Posts: 126
Location: India

 Posted: Mon Dec 27, 2010 6:02 pm Hi, I am trying to make a simple calculator using rexx which can add multiple space separated numbers given in 43*80 screen. say if i give as below (fig-1), in the screen and press enter then should give me sum as 15 fig-1: first line 1 3 5 2nd line 2 4 But when i hit enter my program gets input as 1 3 52 4 . How can restrict them from this unwanted concatenation. I want my program to get input as 1 3 5 2 4 . Please help.
superk

Global Moderator

Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

 Posted: Mon Dec 27, 2010 7:06 pm How exactly are you retrieving that data into your REXX exec? PARSE PULL? What does a Trace show?
prino

Senior Member

Joined: 07 Feb 2009
Posts: 1302
Location: Vilnius, Lithuania

 Posted: Mon Dec 27, 2010 7:40 pm REXX on z/OS has no concept of newlines.
Marso

REXX Moderator

Joined: 13 Mar 2006
Posts: 1353
Location: Israel

Posted: Mon Dec 27, 2010 9:18 pm

On line 12 of you rexx program, use:
 Code: " "
 Code: ||

Guessing not good? then show us what you did!
Susanta

Active User

Joined: 17 Nov 2009
Posts: 126
Location: India

Posted: Tue Dec 28, 2010 11:06 am

 superk wrote: How exactly are you retrieving that data into your REXX exec? PARSE PULL? What does a Trace show?

parse pull ar /* getting the complete data */

/*dividing each line and keeping in array tbl. */
do l= 1 to 42
tbl.l = substr(ar,lineposs,80)
lineposs= lineposs + 80
end

/*storing each number(word) in another array tbl2. */
do ll = 1 to 42
gg = words(tbl.ll)
do ww = 1 to gg
tbl2.gg = word(tbl.ll,ww)
end
end

/* sum */
do i = 1 to tbl2.0
sum = sum + tbl2.i
end
prino

Senior Member

Joined: 07 Feb 2009
Posts: 1302
Location: Vilnius, Lithuania

Posted: Tue Dec 28, 2010 7:00 pm

Susanta wrote:
 superk wrote: How exactly are you retrieving that data into your REXX exec? PARSE PULL? What does a Trace show?

Just one:

Total rubbish, it will never ever work as written, and I am not going to waste my time explaining why.
PeterHolland

Global Moderator

Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

 Posted: Tue Dec 28, 2010 7:05 pm Are you going to use "polish notation" in your calculator? Yes or no makes no difference. Buy one.
Pedro

Global Moderator

Joined: 01 Sep 2006
Posts: 2516
Location: Silicon Valley

Posted: Tue Dec 28, 2010 9:46 pm

 Quote: But when i hit enter my program gets input as 1 3 52 4 . How can restrict them from this unwanted concatenation.

With only one PULL, it seems that you want the user to enter two lines at once. That is the way the emulated hardware works. I do not think you can do anything about it except to train your users.
Susanta

Active User

Joined: 17 Nov 2009
Posts: 126
Location: India

Posted: Thu Dec 30, 2010 2:19 pm

prino wrote:
Susanta wrote:
 superk wrote: How exactly are you retrieving that data into your REXX exec? PARSE PULL? What does a Trace show?

Just one:

Total rubbish, it will never ever work as written, and I am not going to waste my time explaining why.

The below code works fine , provided that new line should start with a '(' .
Not all rubbish .
/**REXX */
mainline:
call initialize
call mainprocess
call termination
exit

initialize:
lineposs = 1
i = 0
k = 0
clear
say 'Provide input as --> + N1 N2 N3 N4 ...NN'
say "start new line with a '('"

parse pull ar
clear
do l= 1 to 3361
if substr(ar,l,1)= "(" then
do
ar = overlay(' ',ar,l)
end
end

k = words(ar)
f = detmine_fun()

return

mainprocess:
sum = 0
mul = 1

Select
when f = '+' then
do ll = 2 to k
sum = sum + word(ar,ll)
s = sum
end
when f = '-' then
do
s = word(ar,2) - word(ar,3)
end

when f = '/' then
do
s = word(ar,2) / word(ar,3)
end

when f = '*' then
do ll = 2 to k
mul = mul * word(ar,ll)
s = mul
end
End
return

termination:
say 'Result = ' s
return

detmine_fun:
df_fun = ' '
df_fun = word(ar,1)
If df_fun = '+' | df_fun = '-' | df_fun = '*' | df_fun = '/' then
nop
else
do
say fucntion not valid
exit
end
return df_fun

/**END- OF -PGM */
dbzTHEdinosauer

Global Moderator

Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

 Posted: Thu Dec 30, 2010 2:43 pm garbage you should be using a panel........... and you should look at NUMERIC DIGITS. otherwise your little script is not worth much
Susanta

Active User

Joined: 17 Nov 2009
Posts: 126
Location: India

 Posted: Thu Dec 30, 2010 2:49 pm You can say garbage its your wish. I build it for quick users for developers who often needs open a calculator for addition ,not a user friendly type with lot of message prompt. If there if finds any non numeric data rexx automatically give an error. if i use a panel then it will take again lot of key pressing.
expat

Global Moderator

Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

 Posted: Thu Dec 30, 2010 2:53 pm Explain how using a panel involves extra key strokes
dbzTHEdinosauer

Global Moderator

Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

 Posted: Thu Dec 30, 2010 3:06 pm if you are going to build a calculator, create a hexidecimal calculator. anyone who can not add and subtract decimal numbers in their head/on a piece of paper needs more help than a calculator. Expat, you know that he is going to answer with somekind of silliness, because he is not going to admit that his little toy, as it is, is useless. not to mention, requires a complete session, instead of a 'pop-up panel' that would be interactive.
Susanta

Active User

Joined: 17 Nov 2009
Posts: 126
Location: India

 Posted: Thu Dec 30, 2010 3:09 pm If i use a normal calculator where 0-9 digits and signs will be there. Then if i try to add 9,3,4. then press + then press 9 then + then 3 like this. But in my program you can paste a list of numbers by copying from any where , no need of doing extensive data entry . But in general calculators you have to enter each and every numbers and also the sign again and again. I dont see any real difference using a panel . yes if i use a panel it will look good .
expat

Global Moderator

Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

Posted: Thu Dec 30, 2010 3:15 pm

Here's a quick and dirty calculator which offers greater functionality,
However, Oh My God, it does involve extra key strokes
 Code: /* REXX *** QUICK AND DIRTY CALCULATOR                               */                                                                         DO FOREVER                                                                EXPLINE = " "                                                          EXPOUT  = " "                                                          "ISPEXEC DISPLAY PANEL(CALC02)"                                        IF RC <> 0 THEN EXIT                                                    INTERPRET "EXPOUT = " EXPLINE                                          "ISPEXEC DISPLAY PANEL(CALC02)"                                      END

Panel
 Code: )ATTR                                                                   # TYPE(OUTPUT) INTENS(LOW) JUST(ASIS) COLOR(WHITE)                     + TYPE(TEXT) INTENS(LOW) CAPS(ON) JUST(LEFT) COLOR(GREEN)               _ TYPE(INPUT) INTENS(LOW) CAPS(ON) JUST(LEFT) COLOR(WHITE)             % TYPE(INPUT) INTENS(HIGH) CAPS(ON) JUST(LEFT) COLOR(RED)              )BODY                                                                  %COMMAND ===>_ZCMD                                +                    +                                                                      + EXPRESSION >>> _EXPLINE                                              +                                                                      + RESULT     >>> _EXPOUT                                                +                                                                      +                                                                      )INIT                                                                    .CURSOR = EXPLINE                                                    )END

Example
 Code: EXPRESSION >>>  14 + ((28 * 7) / 4) - -9 + 11                                                            RESULT     >>>  83
dbzTHEdinosauer

Global Moderator

Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

 Posted: Thu Dec 30, 2010 3:29 pm Expat, yours is probably the best post of the year.
expat

Global Moderator

Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

Posted: Thu Dec 30, 2010 3:41 pm

Dick thank you
Wonder if the code gets plagerised

I did have another quick play just to be able to add the option of lazy addition
 Code: /* REXX *** QUICK AND DIRTY CALCULATOR                               */                                                                         DO FOREVER                                                                F       = " "                                                          EXPLINE = " "                                                          EXPOUT  = " "                                                          "ISPEXEC DISPLAY PANEL(CALC02)"                                        IF RC <> 0 THEN EXIT                                                    IF F <> '' THEN DO                                                        WS = WORDS(EXPLINE)                                                    EXPTMP = WORD(EXPLINE,1) "+"                                            DO AA = 2 TO WS                                                          EXPTMP = EXPTMP WORD(EXPLINE,AA)                                        IF AA < WS                                                                 THEN EXPTMP = EXPTMP "+"                                          END                                                                    EXPLINE = EXPTMP                                                      END                                                                    INTERPRET "EXPOUT = " EXPLINE    "ISPEXEC DISPLAY PANEL(CALC02)" END

The amended panel
 Code: ***************************** Top of Data ****************************** )ATTR                                                                     # TYPE(OUTPUT) INTENS(LOW) JUST(ASIS) COLOR(WHITE)                       + TYPE(TEXT) INTENS(LOW) CAPS(ON) JUST(LEFT) COLOR(GREEN)               _ TYPE(INPUT) INTENS(LOW) CAPS(ON) JUST(LEFT) COLOR(WHITE)               % TYPE(INPUT) INTENS(HIGH) CAPS(ON) JUST(LEFT) COLOR(RED)              )BODY                                                                    %COMMAND ===>_ZCMD                                +                      +                                                                        + FUNCTION   >>> _F+ ENTER ANY CHARACTER TO MAKE THIS A LAZY ADDITION  + + EXPRESSION >>> _EXPLINE                                              + +                                                                        + RESULT     >>> _EXPOUT                                               + +                                                                        +                                                                        )INIT                                                                      .CURSOR = F                                                            )END

The amended example
 Code: FUNCTION   >>>  X  ENTER ANY CHARACTER TO MAKE THIS A LAZY ADDITION    EXPRESSION >>>  1 2 3 4 5 6                                                                                                        RESULT     >>>  21
PeterHolland

Global Moderator

Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

 Posted: Thu Dec 30, 2010 3:59 pm expat, can you do that too for : divisions, subtractions, multiplications and all the other hocus pocus in mathematics? Just for the lazy ones amongst us?
expat

Global Moderator

Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

 Posted: Thu Dec 30, 2010 4:20 pm Peter, I would reply but couldn't be bothered to do the extra key strokes
PeterHolland

Global Moderator

Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

 Posted: Thu Dec 30, 2010 4:26 pm Expat, that makes you the top lazy one between us. Congratulations.
expat

Global Moderator

Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

 Posted: Thu Dec 30, 2010 4:29 pm WOW, two awards on the same day I think I need to find a speech writer for all of my acceptance speeches
PeterHolland

Global Moderator

Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

 Posted: Thu Dec 30, 2010 4:32 pm Yes Expat, maybe i could be the one. After happy hour my speeches are tremendous, but that is once a week.
 View Bookmarks All times are GMT + 6 Hours

 Topic Forum Replies Similar Topics REXX - Do - Not able to LOOP CLIST & REXX 10 Rexx log capturing CLIST & REXX 15 REXX code to expand copybook in a cob... CLIST & REXX 2 Error while running web tool kit REXX... CLIST & REXX 5 Rexx formatting CLIST & REXX 2
Search our Forums:

 IBMMainframes.com is not an official and/or affiliated with IBM® in anyway Board Rules | FAQ | Downloads | Wiki | SiteMap | Contact Us