Page 1 of 1

Passing Stem Variable between Procedures.

PostPosted: Mon Jul 02, 2012 6:03 am
by bazzigar
Hello,

take a look at the below program and please tell me wats wrong in that,
I want the output like,
Hello One
Hello Two
Hello Three
Hello There again

/*REXX*/
Var1.1='Hello One'
Var1.2='Hello Two'
Var1.3='Hello Three'
Var3="Hello There again"
Call SayThat Var1.,Var3
SayThat:Procedure
Count.=ARG(1)
Do i=1 to 3
Say Count.i
End
Say ARG(2)

But the actual output like below,

VAR1.
VAR1.
VAR1.
Hello There again

Thanks,

Re: Passing Stem Variable between Procedures.

PostPosted: Thu Jul 05, 2012 9:34 pm
by Pedro
The PROCEDURE statement fences off variables. The statements within the procedure cannot reference the variables outside of the procedure, without specifying in the PROCEDURE EXPOSE clause. But using EXPOSE makes passing in the name of the stem less attractive.

Try the same (more or less) without PROCEDURE:
/*REXX*/                 
Var1.1='Hello One'       
Var1.2='Hello Two'       
Var1.3='Hello Three'     
Var3="Hello There again"
Call SayThat Var1.,Var3 
Exit                     
                         
SayThat:                 
Count=ARG(1)             
Do i=1 to 3             
 Interpret "Say "Count"i"
End                     
Say ARG(2)               


The other odd thing is that Var1. is a valid variable, different from the var1.x set of variables. But for uninitialized variables, rexx uses the name of the variable as its value (same as: abc ='abc' ). I think it is poor practice to rely on uninitialized variables, so perhaps use a quoted string instead:
Call SayThat 'Var1.',Var3

Re: Passing Stem Variable between Procedures.

PostPosted: Fri Jul 06, 2012 10:19 am
by bazzigar
Pedro wrote:The PROCEDURE statement fences off variables. The statements within the procedure cannot reference the variables outside of the procedure, without specifying in the PROCEDURE EXPOSE clause. But using EXPOSE makes passing in the name of the stem less attractive.

Try the same (more or less) without PROCEDURE:
/*REXX*/                 
Var1.1='Hello One'       
Var1.2='Hello Two'       
Var1.3='Hello Three'     
Var3="Hello There again"
Call SayThat Var1.,Var3 
Exit                     
                         
SayThat:                 
Count=ARG(1)             
Do i=1 to 3             
 Interpret "Say "Count"i"
End                     
Say ARG(2)               


The other odd thing is that Var1. is a valid variable, different from the var1.x set of variables. But for uninitialized variables, rexx uses the name of the variable as its value (same as: abc ='abc' ). I think it is poor practice to rely on uninitialized variables, so perhaps use a quoted string instead:
Call SayThat 'Var1.',Var3





Thank you so much Pedro for yor reply.It helps me.