Dear support,
I'm using the tool since a certain time and I really like it
However, In my opinion is really a pity that there is no implementation of a FUNCTION feature to get back variables in a safe way.
Anyway, I use SRT feature with the LOCALVARS paradigm.
I have carefully read the definition of Local Scope for variables, but something is not yet clear to me. I still experiment unexpected behaviors with variable localization.
Can someone explain me what is wrong and how should I use correctly LOCALVARS?
Simple example:
==============
' Global variables
Let>var_a=1
Let>var_b=2
Let>var_c=3
Let>Var_d=4
Gosub>Level1
SRT>Level1
Let>LOCALVARS=1
Let>var_d=2
Let>var_a=100
GoSub>Level2
Let>LOCALVARS=1
' Puts back environment to scope 1
' Result is 3 as expected
Let>var_d=var_d+1
'Result=11 , why? , should be 101 that is var_a in level 1
'Instead var_a works with global scope
Let>var_a=var_a+1
END>Level1
SRT>Level2
Let>LOCALVARS=1
Gosub>Level3
Let>var_a=200
' result is 201 as expected
Let>var_a=var_a+1
END>Level2
SRT>Level3
Let>LOCALVARS=1
Let>var_d=300
Let>LOCALVARS=0
Let>var_a=10
' Put back to level 3
Let>LOCALVARS=1
' result is 301 as expected
Let>var_d=var_d+1
END>Level3
Unexpected results by using LOCALVARS
Moderators: Dorian (MJT support), JRL
- Grovkillen
- Automation Wizard
- Posts: 1131
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: Unexpected results by using LOCALVARS
Code: Select all
SRT>Level1
Let>LOCALVARS=1
Let>var_d=2
Let>var_a=100
GoSub>Level2
Let>LOCALVARS=1
' Puts back environment to scope 1
' Result is 3 as expected
Let>var_d=var_d+1
'Result=11 , why? , should be 101 that is var_a in level 1
'Instead var_a works with global scope
Let>var_a=var_a+1
END>Level1
Look in the beginning, you never set it to zero
Re: Unexpected results by using LOCALVARS
Thanks for the reply.
But, sorry I cannot catch my error.
Could you be more explicit?
What do you mean I never never set it to zero?
Massimo
But, sorry I cannot catch my error.
Could you be more explicit?
What do you mean I never never set it to zero?
Massimo
Re: Unexpected results by using LOCALVARS
In SRT Level3 you set LOCALVARS=0 and then directly set var_a=10.
Since LOCALVARS is turned off you effectively change var_a to 10 for all levels (if you step through the script, you see that var_a, for both level 0 and for level 1, change from 1 and 100, to 10 respectively).
Since LOCALVARS is turned off you effectively change var_a to 10 for all levels (if you step through the script, you see that var_a, for both level 0 and for level 1, change from 1 and 100, to 10 respectively).
Re: Unexpected results by using LOCALVARS
yes, but the intent of my example in SRT level 3 is to change var_a of level 0 without affecting the other localized var_a in other levels. How to do this?
In my example var-a of level 2 is not affected, but var_a of level1 it is.
To be honest I have a lot of pain to understand the behavior of variable localization with MS.
It is a pity that there is no implementation of Functions to handle variable scope in a simpler way
In my example var-a of level 2 is not affected, but var_a of level1 it is.
To be honest I have a lot of pain to understand the behavior of variable localization with MS.
It is a pity that there is no implementation of Functions to handle variable scope in a simpler way
Re: Unexpected results by using LOCALVARS
Hi,
I have had similar problems in the past to get it to work as I want, so what I do now (for non-simple cases), is to have unique variable names in each SRT, eg in your case L0_var_a , L1_var_a, and L2_var_a and then define where it should affect the global variable var_a.
In level 2, if you add a MDL>var_a you can see it shows 10 as well before you set it to 200.In my example var-a of level 2 is not affected, but var_a of level1 it is.
I have had similar problems in the past to get it to work as I want, so what I do now (for non-simple cases), is to have unique variable names in each SRT, eg in your case L0_var_a , L1_var_a, and L2_var_a and then define where it should affect the global variable var_a.
Re: Unexpected results by using LOCALVARS
Thanks for your recommendation.
In fact is what I do also to prevent problems.
However I find that this is a week point MS.
I try to make the most possible reusable code.
So I develop routines and I include when necessary in my code.
Today I'm facing similar problems as explained in the example in a 5000 lines code program with different include sections. I'm quite frustrated to see that some time I spend more time to debug issues with localized variables than develop the code.
In my side, I would pay the double the license cost of MS if a better implementation of variables & function paradigm to pass back parameters would be developed
In fact is what I do also to prevent problems.
However I find that this is a week point MS.
I try to make the most possible reusable code.
So I develop routines and I include when necessary in my code.
Today I'm facing similar problems as explained in the example in a 5000 lines code program with different include sections. I'm quite frustrated to see that some time I spend more time to debug issues with localized variables than develop the code.
In my side, I would pay the double the license cost of MS if a better implementation of variables & function paradigm to pass back parameters would be developed