View previous topic :: View next topic
|
Author |
Message |
Susanta
Active User
Joined: 17 Nov 2009 Posts: 129 Location: India
|
|
|
|
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 |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
How exactly are you retrieving that data into your REXX exec? PARSE PULL? What does a Trace show? |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1314 Location: Vilnius, Lithuania
|
|
|
|
REXX on z/OS has no concept of newlines. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
On line 12 of you rexx program, use:
instead of
Guessing not good? then show us what you did! |
|
Back to top |
|
|
Susanta
Active User
Joined: 17 Nov 2009 Posts: 129 Location: India
|
|
|
|
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 |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1314 Location: Vilnius, Lithuania
|
|
|
|
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 |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Are you going to use "polish notation" in your calculator? Yes or no makes
no difference. Buy one. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2593 Location: Silicon Valley
|
|
|
|
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 |
|
|
Susanta
Active User
Joined: 17 Nov 2009 Posts: 129 Location: India
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Susanta
Active User
Joined: 17 Nov 2009 Posts: 129 Location: India
|
|
|
|
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 |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Explain how using a panel involves extra key strokes |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Susanta
Active User
Joined: 17 Nov 2009 Posts: 129 Location: India
|
|
|
|
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 |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Expat,
yours is probably the best post of the year. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
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 |
|
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
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?
|
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Peter, I would reply but couldn't be bothered to do the extra key strokes |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Expat,
that makes you the top lazy one between us. Congratulations. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
WOW, two awards on the same day
I think I need to find a speech writer for all of my acceptance speeches |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Yes Expat, maybe i could be the one. After happy hour my speeches are
tremendous, but that is once a week. |
|
Back to top |
|
|
|