IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Rexx Calculator


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Susanta

Active User


Joined: 17 Nov 2009
Posts: 129
Location: India

PostPosted: Mon Dec 27, 2010 6:02 pm
Reply with quote

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.
Back to top
View user's profile Send private message
superk

Global Moderator


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

PostPosted: Mon Dec 27, 2010 7:06 pm
Reply with quote

How exactly are you retrieving that data into your REXX exec? PARSE PULL? What does a Trace show?
Back to top
View user's profile Send private message
prino

Senior Member


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

PostPosted: Mon Dec 27, 2010 7:40 pm
Reply with quote

REXX on z/OS has no concept of newlines.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Dec 27, 2010 9:18 pm
Reply with quote

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

Guessing not good? then show us what you did!
Back to top
View user's profile Send private message
Susanta

Active User


Joined: 17 Nov 2009
Posts: 129
Location: India

PostPosted: Tue Dec 28, 2010 11:06 am
Reply with quote

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


Please see below and let me know your comments.

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
Back to top
View user's profile Send private message
prino

Senior Member


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

PostPosted: Tue Dec 28, 2010 7:00 pm
Reply with quote

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


Please see below and let me know your comments.


My comments?

Just one:

Total rubbish, it will never ever work as written, and I am not going to waste my time explaining why.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


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

PostPosted: Tue Dec 28, 2010 7:05 pm
Reply with quote

Are you going to use "polish notation" in your calculator? Yes or no makes
no difference. Buy one.
Back to top
View user's profile Send private message
Pedro

Global Moderator


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

PostPosted: Tue Dec 28, 2010 9:46 pm
Reply with quote

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.
Back to top
View user's profile Send private message
Susanta

Active User


Joined: 17 Nov 2009
Posts: 129
Location: India

PostPosted: Thu Dec 30, 2010 2:19 pm
Reply with quote

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


Please see below and let me know your comments.


My comments?

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 */
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Dec 30, 2010 2:43 pm
Reply with quote

garbage

you should be using a panel...........

and you should look at NUMERIC DIGITS.
otherwise your little script is not worth much
Back to top
View user's profile Send private message
Susanta

Active User


Joined: 17 Nov 2009
Posts: 129
Location: India

PostPosted: Thu Dec 30, 2010 2:49 pm
Reply with quote

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.
Back to top
View user's profile Send private message
expat

Global Moderator


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

PostPosted: Thu Dec 30, 2010 2:53 pm
Reply with quote

Explain how using a panel involves extra key strokes
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Dec 30, 2010 3:06 pm
Reply with quote

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.
Back to top
View user's profile Send private message
Susanta

Active User


Joined: 17 Nov 2009
Posts: 129
Location: India

PostPosted: Thu Dec 30, 2010 3:09 pm
Reply with quote

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 .
Back to top
View user's profile Send private message
expat

Global Moderator


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

PostPosted: Thu Dec 30, 2010 3:15 pm
Reply with quote

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 
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Dec 30, 2010 3:29 pm
Reply with quote

Expat,

yours is probably the best post of the year.
Back to top
View user's profile Send private message
expat

Global Moderator


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

PostPosted: Thu Dec 30, 2010 3:41 pm
Reply with quote

Dick icon_redface.gif thank you
Wonder if the code gets plagerised icon_lol.gif

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           
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


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

PostPosted: Thu Dec 30, 2010 3:59 pm
Reply with quote

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?

icon_rolleyes.gif
Back to top
View user's profile Send private message
expat

Global Moderator


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

PostPosted: Thu Dec 30, 2010 4:20 pm
Reply with quote

Peter, I would reply but couldn't be bothered to do the extra key strokes icon_lol.gif
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


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

PostPosted: Thu Dec 30, 2010 4:26 pm
Reply with quote

Expat,

that makes you the top lazy one between us. Congratulations. icon_lol.gif
Back to top
View user's profile Send private message
expat

Global Moderator


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

PostPosted: Thu Dec 30, 2010 4:29 pm
Reply with quote

WOW, two awards on the same day icon_redface.gif

I think I need to find a speech writer for all of my acceptance speeches icon_biggrin.gif
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


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

PostPosted: Thu Dec 30, 2010 4:32 pm
Reply with quote

Yes Expat, maybe i could be the one. After happy hour my speeches are
tremendous, but that is once a week. icon_rolleyes.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Does anyone know rexx for VSE CLIST & REXX 3
No new posts TSO ALLOC In REXX Needs Improvement JCL & VSAM 3
No new posts REXX/CMS How to place command console... CLIST & REXX 4
No new posts Help needed in automation cics transa... CLIST & REXX 1
No new posts Reroute print output via REXX/SDSF TSO/ISPF 6
Search our Forums:

Back to Top