Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Rexx Calculator
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
View previous topic :: :: View next topic  
Author Message
Susanta

Active User


Joined: 17 Nov 2009
Posts: 118
Location: India

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

Moderator Team Head


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

PostPosted: Mon Dec 27, 2010 7:06 pm    Post subject: Reply to: Rexx Calculator
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

Active Member


Joined: 07 Feb 2009
Posts: 982
Location: Oostende, Belgium

PostPosted: Mon Dec 27, 2010 7:40 pm    Post subject:
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: 1219
Location: Israel

PostPosted: Mon Dec 27, 2010 9:18 pm    Post subject: Reply to: Rexx Calculator
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: 118
Location: India

PostPosted: Tue Dec 28, 2010 11:06 am    Post subject: Re: Reply to: Rexx Calculator
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

Active Member


Joined: 07 Feb 2009
Posts: 982
Location: Oostende, Belgium

PostPosted: Tue Dec 28, 2010 7:00 pm    Post subject: Re: Reply to: Rexx Calculator
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: 2422
Location: Netherlands, Amstelveen

PostPosted: Tue Dec 28, 2010 7:05 pm    Post subject:
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

Senior Member


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

PostPosted: Tue Dec 28, 2010 9:46 pm    Post subject: Reply to: Rexx Calculator
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: 118
Location: India

PostPosted: Thu Dec 30, 2010 2:19 pm    Post subject: Re: Reply to: Rexx Calculator
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    Post subject:
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: 118
Location: India

PostPosted: Thu Dec 30, 2010 2:49 pm    Post subject:
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: 8593
Location: Back in jolly old England

PostPosted: Thu Dec 30, 2010 2:53 pm    Post subject:
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    Post subject:
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: 118
Location: India

PostPosted: Thu Dec 30, 2010 3:09 pm    Post subject:
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: 8593
Location: Back in jolly old England

PostPosted: Thu Dec 30, 2010 3:15 pm    Post subject:
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    Post subject:
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: 8593
Location: Back in jolly old England

PostPosted: Thu Dec 30, 2010 3:41 pm    Post subject:
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: 2422
Location: Netherlands, Amstelveen

PostPosted: Thu Dec 30, 2010 3:59 pm    Post subject:
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: 8593
Location: Back in jolly old England

PostPosted: Thu Dec 30, 2010 4:20 pm    Post subject:
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: 2422
Location: Netherlands, Amstelveen

PostPosted: Thu Dec 30, 2010 4:26 pm    Post subject:
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts What is the command to check MODE of ... rohanthengal CLIST & REXX 6 Fri Nov 18, 2016 1:48 pm
This topic is locked: you cannot edit posts or make replies. Rexx to create GDG by scanning JJ result krish.deepu CLIST & REXX 5 Tue Oct 25, 2016 5:32 pm
No new posts Replace repeated JCL with looping REXX prino CLIST & REXX 3 Thu Oct 13, 2016 5:30 am
This topic is locked: you cannot edit posts or make replies. Need to code a Rexx PGM sundaram.naveen CLIST & REXX 18 Thu Oct 06, 2016 6:45 pm
No new posts Need Rexx Program to Load in to DB2 T... Hareesh Verma CLIST & REXX 22 Tue Sep 20, 2016 2:59 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us