Portal | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

 Rexx Calculator Goto page 1, 2  Next
Author Message
Susanta

Active User

Joined: 17 Nov 2009
Posts: 126
Location: India

 Posted: Mon Dec 27, 2010 6:02 pm    Post subject: Rexx Calculator 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

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

 Posted: Mon Dec 27, 2010 7:06 pm    Post subject: Reply to: Rexx Calculator 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: 1220
Location: Vilnius, Lithuania

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

REXX Moderator

Joined: 13 Mar 2006
Posts: 1348
Location: Israel

Posted: Mon Dec 27, 2010 9:18 pm    Post subject: Reply to: Rexx Calculator

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    Post subject: Re: Reply to: Rexx Calculator

 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: 1220
Location: Vilnius, Lithuania

Posted: Tue Dec 28, 2010 7:00 pm    Post subject: Re: Reply to: Rexx Calculator

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: 2476
Location: Netherlands, Amstelveen

 Posted: Tue Dec 28, 2010 7:05 pm    Post subject: 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: 2205
Location: Silicon Valley

Posted: Tue Dec 28, 2010 9:46 pm    Post subject: Reply to: Rexx Calculator

 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    Post subject: Re: Reply to: Rexx Calculator

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: 6970
Location: porcelain throne

 Posted: Thu Dec 30, 2010 2:43 pm    Post subject: 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    Post subject: 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: 8796
Location: Welsh Wales

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

Global Moderator

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

 Posted: Thu Dec 30, 2010 3:06 pm    Post subject: 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    Post subject: 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: 8796
Location: Welsh Wales

Posted: Thu Dec 30, 2010 3:15 pm    Post subject:

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: 6970
Location: porcelain throne

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

Global Moderator

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

Posted: Thu Dec 30, 2010 3:41 pm    Post subject:

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: 2476
Location: Netherlands, Amstelveen

 Posted: Thu Dec 30, 2010 3:59 pm    Post subject: 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: 8796
Location: Welsh Wales

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

Global Moderator

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

 Posted: Thu Dec 30, 2010 4:26 pm    Post subject: Expat, that makes you the top lazy one between us. Congratulations.
 All times are GMT + 6 HoursGoto page 1, 2  Next
 Page 1 of 2

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics REXX script to beautify XML jzhardy CLIST & REXX 1 Sun Oct 11, 2020 1:23 pm TWS PIF (EQQYCOM) Rexx - Occurrence S... Richard Baker IBM Tools 0 Wed Sep 16, 2020 10:45 am Call Natural program with rexx shahaf CLIST & REXX 2 Tue Sep 08, 2020 11:22 am CA Sysview - JCL or Rexx - Read or Ex... Jasi CA Products 4 Wed Aug 05, 2020 9:19 pm Invoke REXX thru JCL to expand the co... spizen556 CLIST & REXX 2 Sun Jul 26, 2020 3:53 pm

 © 2003-2020 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us