In a local subroutine, the control variables are not local, which may lead to problems if a subroutine calls another one which use control variables named identically. I think this is quite likely to happen if for loops are used in generic subroutines shared between different programs though the use of he include command (as was my case).
This undesirable behaviour is present in both EViews versions 7.2 and 8.
Here's a simple example:
Code: Select all
subroutine local test1
%i = "a"
!i = 1
endsub
subroutine local test2(string %out)
%i = "b"
!i = 2
call test1
%out = %i + @str(!i)
endsub
%str = ""
call test2(%str)
@uiprompt(%str)
As a workaround, for the moment, I use the fact that the variables appearing as arguments are truly local and behave correctly, so I put the control variables as arguments. To keep the subroutine "interface" clean, I define a first routine with the expected arguments, and this routine calls a second one which includes additional arguments for the control variables. For example, the above example would become like this:
Code: Select all
subroutine local test1
call test1_args("", 0)
endsub
subroutine local test1_args(string %i, scalar !i)
%i = "a"
!i = 1
endsub
subroutine local test2(string %out)
call test2_args(%out, "", 0)
endsub
subroutine local test2_args(string %out, string %i, scalar !i)
%i = "b"
!i = 2
call test1
%out = %i + @str(!i)
endsub
%str = ""
call test2(%str)
@uiprompt(%str)
Best regards,
Étienne
