Passing objects and variables between multiple programs

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

Florek
Posts: 2
Joined: Fri Feb 07, 2020 7:32 am

Passing objects and variables between multiple programs

Postby Florek » Fri Feb 07, 2020 9:08 am

Dear Eviewers,

I have several very long codes which I uses for different central bank analysis. As these codes are very similar, I would like to split the codes in different smaller programs using exec and use variables as placeholder whenever possible.

More precisely, suppose the first program is a master file where I define different parameters such as

Frist Program “Master file”

Code: Select all

'choose CB %CB = "fed" !model = 1 ‘Only string objects are passed to other programs string CB = %CB exec .\List_of_variables.prg scalar test1 = num_var_dep scalar test2 = !num_var_inf
From this I want to call a second program “list_of_variables”

Code: Select all

if CB = "fed" then 'Create list of dependent variables string list_var_dep = "A B C" scalar num_var_dep = @wcount(list_var_dep) 'Create list of inflation %list_var_inf = "X Y Z" !num_var_inf = @wcount(%list_var_inf) endif
If I run the master file test1 = 3 but test2 is empty. Also, if the if-statement would read as

Code: Select all

if %CB = "fed" then
both would be empty. In other words, only strings or scalar objects can be passed around between different programs but not variables such as “%list_var_inf” or “!num_var_inf”.

Why is this the case and how can I pass variables between different programs?

Later I want to loop over the list of variables, so string objects would not work. I could probably redefined string objects to variables (%list_var_dep = list_var_dep), but I think this is not very handy as I am doing this for several input / output variables. Also, I assume it must somehow be possible to pass variables to other programs.

Thanks a lot for your help in advance!

Best,
Florian

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13602
Joined: Tue Sep 16, 2008 5:38 pm

Re: Passing objects and variables between multiple programs

Postby EViews Gareth » Fri Feb 07, 2020 9:12 am

Using include rather than exec is probably the best option.

Florek
Posts: 2
Joined: Fri Feb 07, 2020 7:32 am

Re: Passing objects and variables between multiple programs

Postby Florek » Mon Feb 10, 2020 3:05 am

Thanks a lot. This works perfectly!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests