CD to path in string

For questions regarding programming in the EViews programming language.

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

wjgatt
Posts: 30
Joined: Fri Jan 27, 2012 3:52 am

CD to path in string

Postby wjgatt » Tue Sep 06, 2016 4:02 am

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

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

Re: CD to path in string

Postby EViews Gareth » Tue Sep 06, 2016 8:16 am

I don't follow.

pricest
Posts: 2
Joined: Tue Sep 06, 2016 6:18 pm

Re: CD to path in string

Postby pricest » Tue Sep 06, 2016 6:31 pm

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!!!!!!

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

Re: CD to path in string

Postby EViews Gareth » Tue Sep 06, 2016 7:26 pm

Code: Select all

wfopen(page={%PageArea})

wjgatt
Posts: 30
Joined: Fri Jan 27, 2012 3:52 am

Re: CD to path in string

Postby wjgatt » Tue Sep 06, 2016 9:52 pm

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

dakila
Posts: 489
Joined: Tue Nov 24, 2015 4:57 pm

Re: CD to path in string

Postby dakila » Tue Sep 06, 2016 10:06 pm

You do not need to create the string. Just use the following code after your code.

Code: Select all

cd routines include preliminaries.prg

wjgatt
Posts: 30
Joined: Fri Jan 27, 2012 3:52 am

Re: CD to path in string

Postby wjgatt » Wed Sep 07, 2016 12:07 am

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

dakila
Posts: 489
Joined: Tue Nov 24, 2015 4:57 pm

Re: CD to path in string

Postby dakila » Wed Sep 07, 2016 12:27 am

Code: Select all

cd routines include preliminaries.prg cd %run_path

wjgatt
Posts: 30
Joined: Fri Jan 27, 2012 3:52 am

Re: CD to path in string

Postby wjgatt » Wed Sep 07, 2016 12:55 am

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.

pricest
Posts: 2
Joined: Tue Sep 06, 2016 6:18 pm

Re: CD to path in string

Postby pricest » Wed Sep 07, 2016 12:55 pm

Code: Select all

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

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

Re: CD to path in string

Postby EViews Gareth » Wed Sep 07, 2016 1:30 pm

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

wjgatt
Posts: 30
Joined: Fri Jan 27, 2012 3:52 am

Re: CD to path in string

Postby wjgatt » Sun Sep 11, 2016 10:30 pm

Yes that seems to have solved my issue, thanks Gareth!

W


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests