Page 1 of 2

Dynamic populate the value inside user function

PostPosted: Wed Sep 19, 2012 12:59 am
by Amit_learn
IF IND='P' THEN DYNDATA="'4','INVALID CHOICE'"
ELSE DYNDATA="'5','AGAIN"

XX = FUNC(VAL,'1','RED','2','WHITE',
        '3','NO COLOR',DYNDATA,' ',' ')
FUNC:
    DO I = 2 TO ARG() BY 2
      SAY ARG(I) ';' ARG(I+1)
    END
RETURN 0
***************************
Required Output:
1;RED
2;WHITE
3;NO COLOR
4;INVALID CHOICE

I am getting the 1,2,3 correctly but for 4/5, depending upon the IND I have set the DYNDATA dynamically and use it into FUNC.
But when I am passing DYNDATA as "'4','INVALID CHOICE'", not getting the correct output (4,INVALID CHOICE; ).
Any suggestion?

Re: Dynamic populate the value inside user function

PostPosted: Wed Sep 19, 2012 1:09 am
by Akatsukami
And what did the trace show you?

Re: Dynamic populate the value inside user function

PostPosted: Wed Sep 19, 2012 1:35 am
by enrico-sorichetti
Any suggestion?

strong suggestion
read the rexx manuals about the rules for passing parameters to rexx functions/subroutines

hint ...
the way You do it
arg(8) contains the whole <message>
according to Your coding You expect 11 arguments
the VAL thing + 5 couples

when really the call is passing just 10 ( as per rexx rules )

change Your function to
FUNC:
say arg()
DO I = 2 TO ARG() BY 2
SAY i ">"ARG(I)"<" ';' i+1 ">"ARG(I+1)"<"
END
RETURN 0

and You will see the problem

here is the link to the rexx manuals
http://publibz.boulder.ibm.com/cgi-bin/ ... s/IKJ4BK90

not the latest ones but more than enough

Re: Dynamic populate the value inside user function

PostPosted: Wed Sep 19, 2012 6:22 am
by delorimier
It looks like there is a single quote missing just after the word AGAIN. Could it be the problem?

Rene

Re: Dynamic populate the value inside user function

PostPosted: Wed Sep 19, 2012 12:52 pm
by prino
delorimier wrote:It looks like there is a single quote missing just after the word AGAIN. Could it be the problem?

You're missing the issue by about a mile...

Re: Dynamic populate the value inside user function

PostPosted: Wed Sep 19, 2012 6:03 pm
by delorimier
It was just a suggestion Rob.

But, point taken, I apologize for posting to the forum without having the expertise, and I'll stay quiet from now on.

Yours truly,

Rene

Re: Dynamic populate the value inside user function

PostPosted: Wed Sep 19, 2012 7:20 pm
by BillyBoyo
Rene,

Welcome to the forum. Sometimes you can meet a certain "shortness" here. You then have to take the "rough", but it is not so often.

It may not have been the main point, but no-one else seems to have spotted it :-) Good eyes. You don't need any expertise for that. Perhaps a little more experience before suggesting it as the answer :-)

Feel free to type something when you think you have something. If anything becomes too rough, you'll probably find a Moderator does some tidying-away :-)

Re: Dynamic populate the value inside user function

PostPosted: Wed Sep 19, 2012 8:07 pm
by enrico-sorichetti
It looks like there is a single quote missing just after the word AGAIN. Could it be the problem?

just esthetics, the code would display something different from what it was meant :mrgreen:

meditate on dbz signature
Programming Languages, SQL and JCL have the tendency to do what you coded,
not necessarily what you wanted.


t may not have been the main point, but no-one else seems to have spotted it


... because there was nothing to spot ;)
in REXX strings can be delimited by ' or "

so there is no need to double anything
You need to double only when the character inside the string is the same as the string delimiter

apost = "'"
apost = '''
quote = '"'
quote ="""""
'


ap = "'"
ap1 = ''''
qt = '"'
qt1 = """"
say ap ap1 qt qt1



provide exactly the same functionality

my personal preference is to use "
also provides better readability

Re: Dynamic populate the value inside user function

PostPosted: Wed Sep 19, 2012 8:13 pm
by Akatsukami
delorimier wrote:But, point taken, I apologize for posting to the forum without having the expertise, and I'll stay quiet from now on.

Not a lack of expertise per se, but a lack of understanding of what the TS is trying to accomplish.

As Dr. Sorichetti has indicated, the function func is receiving ten arguments, not eleven. Assigning dyndata a value containing pic marks (single quotes) does not make it multiple arguments when simply passed to a function (using INTERPRET would, but that's overkill).

Additionally, the statement
XX = FUNC(VAL,'1','RED','2','WHITE',
        '3','NO COLOR',DYNDATA,' ',' ')

is missing a comma on the first line. The trailing comma is interpreted as a line continuation character, not a parameter separator. This causes the literals "WHITE" and "3" to be interpreted as a single argument, with a space infixed.

Re: Dynamic populate the value inside user function

PostPosted: Wed Sep 19, 2012 8:17 pm
by enrico-sorichetti
I considered the missing comma as a cut and paste error
but if the code was as as posted it should be considered a programming error

it is a pity that REXX ( any flavor ) does not raise the NOVALUE exception for arguments out of range !
confirmed by testing :geek: