call by reference - help required urgent

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
yuvaraj
Newbie
Posts: 5
Joined: Tue Jun 16, 2009 2:32 pm

call by reference - help required urgent

Post by yuvaraj » Fri Jul 03, 2009 7:35 am

hello,

I am trying to the following:

Let>VAREXPLICIT=1
Let>var=123
GoSub>PRO,var

SRT>PRO
Let>pro_var=%PRO_Var_1%
END>PRO

I am trying to get the value of 'var' i.e. 123 inside the PRO subroutine. For which I tried to use %%PRO_Var_1%%, which returned the same thing.
I want to know the variable name and value inside the PRO subroutine.

Objective is: Want to get the variable name and its value of the argument that I send to the subroutine.

I am in very much need for the solution. Please someone help me.

Thanks
yuvaraj.

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Jul 03, 2009 10:03 am

The variable name is always PRO_Var_1 and the value is the value of PRO_Var_1

I suppose if you wanted to know the name of the original variable you could pass it as a literal string in a second parm:

Code: Select all

Let>VAREXPLICIT=1
Let>var=123
GoSub>PRO,%var%,var

SRT>PRO
  Let>pro_var_value=%PRO_Var_1%
  Let>pro_var_name=%PRO_Var_2%
END>PRO
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

yuvaraj
Newbie
Posts: 5
Joined: Tue Jun 16, 2009 2:32 pm

Post by yuvaraj » Fri Jul 03, 2009 11:30 am

Thanks for the information.

So, it means there no way I can get it the following way

Code: Select all

Let>VAREXPLICIT=1
Let>var=123
GoSub>PRO,var

SRT>PRO
  Let>pro_var_value=%PRO_Var_1%
........
END>PRO

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

VAREXPLICIT 0 required

Post by gdyvig » Fri Jul 03, 2009 6:49 pm

Hi yuvaraj,

VAREXPLICIT 0 is required to call by reference. Here is how to do it if you want your main script to be VAREXPLICIT 1.

Code: Select all

Let>VAREXPLICIT=1
Let>var=123
GoSub>PRO,var

SRT>PRO
  Let>VAREXPLICIT=0
  Let>pro_var_name=PRO_Var_1
  Let>pro_var_value=%PRO_Var_1%
  Let>VAREXPLICIT=1
  MDL>pro_var_name:%pro_var_name%
  MDL>pro_var_value:%pro_var_value%
END>PRO
Usually in a self contained subroutine you don't care about the name of the variable in the main script. Was your subroutine going to modify the value of var and you wanted to pass it back? Another way to do that is:

Code: Select all

Let>VAREXPLICIT=1
Let>var=123
GoSub>PRO,%var%
Let>var=%pro_var_value%

SRT>PRO
  Let>pro_var_value=%PRO_Var_1%+1
END>PRO

Gale

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts