Page 1 of 1

CD to path in string

Posted: Tue Sep 06, 2016 4:02 am
by wjgatt
I would like to have a program register the path from where it is being run, and then save this as a string. This part is straightforward using @runpath and a string variable. However I would like the main program to include subprograms held in a folder within the main path.

For example:
path for main program C:\Program
path for subprograms C:\Program\subprograms

I have written a string which contains the full path for the subprograms, but I cannot get Eviews to cd to that path by reading the string, and hence cannot have the subprogram run. Any help with this please?

Thanks
W

Re: CD to path in string

Posted: Tue Sep 06, 2016 8:16 am
by EViews Gareth
I don't follow.

Re: CD to path in string

Posted: Tue Sep 06, 2016 6:31 pm
by pricest
I think I am having a similar issue.

I want to loop through a group of strings as variables in order to access different workfile pages. I previously got this to work for creating pages and importing excel files, but never tried directories.

My code [that is NOT working] is

for %Area "Tacoma" "Seattle" "Snohomish"
%PageArea="ZZ_"+%Area
wfopen(page=%PageArea) [Workfile_Path]

[estimation stuff]

next

Right now the workfile only opens to the last save paged because, as I've found, there is a difference between %PageArea and ZZ_Tacoma, as typing ZZ_Tacoma directly in (or using straight pageselect ZZ_Tacoma) with this works.

SO, how can I convert a string variable such that page= will recognize it as a page name and not a string? I need to iterate through like 15 pages for at least 10 different things, so, I need to figure this out.

THANKS!!!!!!

Re: CD to path in string

Posted: Tue Sep 06, 2016 7:26 pm
by EViews Gareth

Code: Select all

wfopen(page={%PageArea})

Re: CD to path in string

Posted: Tue Sep 06, 2016 9:52 pm
by wjgatt
I don't follow.
Probably best if I show you the code:

Code: Select all

%run_path = @runpath cd %run_path [code here] string routine_path = "''" + %run_path + "routines\" + "''" cd {routine_path} include preliminaries.prg
Running the above creates the correct path in the string 'routine_path', but running the program results in a "path or file not found" error, (the program I am calling exists in the subfolder \routines, so the issue must be the path).

Thanks

Re: CD to path in string

Posted: Tue Sep 06, 2016 10:06 pm
by dakila
You do not need to create the string. Just use the following code after your code.

Code: Select all

cd routines include preliminaries.prg

Re: CD to path in string

Posted: Wed Sep 07, 2016 12:07 am
by wjgatt
Thanks for your reply, indeed that does change the path easily, however it turns out that as you run the main program, Eviews checks for the existence of the program called by 'include' in the main directory during the compile(?) stage, before it actually executes anything, and crashes as it does not find it. Still a dead end.

Using 'exec' instead of 'include' works, but from what I understand 'exec' does not cause Eviews to pass on any control/string variables to that program being executed, so no progress there either as Eviews also crashes.

I ended up writing a program holding all the routines I need as subroutines, and I 'call' them when needed in the main program. I still can't get the subroutines program to be in a different path, which is back to my main problem, but at least this is more elegant than having various program files in the main folder.

Thanks
W

Re: CD to path in string

Posted: Wed Sep 07, 2016 12:27 am
by dakila

Code: Select all

cd routines include preliminaries.prg cd %run_path

Re: CD to path in string

Posted: Wed Sep 07, 2016 12:55 am
by wjgatt
That doesn't work for me unfortunately. I'm on Eviews 9.5 Mar 17 build; maybe I need to install the latest patches. Thanks for your help.

Re: CD to path in string

Posted: Wed Sep 07, 2016 12:55 pm
by pricest

Code: Select all

wfopen(page={%PageArea})
great thanks!

Re: CD to path in string

Posted: Wed Sep 07, 2016 1:30 pm
by EViews Gareth
Include happens before anything else, including (pun intended) string allocations, so you cannot include a program dynamically.

You might be able to get away with relative paths:
http://www.eviews.com/download/whitepapers/Paths.pdf

Re: CD to path in string

Posted: Sun Sep 11, 2016 10:30 pm
by wjgatt
Yes that seems to have solved my issue, thanks Gareth!

W