Hello,
I need advice on applying relative pathways in program files.
I have several program files. They're structured in a way where I have one primary program file that calls on several supplementary program files (which do things like import/export excel files). All of them have the same path (or are in the same folder), but because they're hardcoded, I have to change the pathway of each of the program files.
Is there a way I can put the pathway just once in the primary program file and have the supplementary program files adopt the same pathway specified in the primary program file?
Thank you for your time.
Relative pathways
Moderators: EViews Gareth, EViews Moderator
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13600
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Relative pathways
Thank you for this.
I may need a bit more help though if it is all right.
Say I have two program files (1) primary.prg and (2) secondary.prg in the folder "C:\Documents\Main Directory".
How do I get (2) secondary.prg to adopt the same path specified in (1) primary.prg?
For example, if (1) primary.prg has the following path which the secondary program file adopts:
How do I get (2) secondary.prg to adopt something like:
How would I get the secondary.prg to use the file path specified in the primary.prg?
Thank you for your time.
I may need a bit more help though if it is all right.
Say I have two program files (1) primary.prg and (2) secondary.prg in the folder "C:\Documents\Main Directory".
How do I get (2) secondary.prg to adopt the same path specified in (1) primary.prg?
For example, if (1) primary.prg has the following path which the secondary program file adopts:
Code: Select all
'Primary program file
%main_directory = "C:\Documents\Main Directory\"
Code: Select all
Secondary program file
excel_final_path = %main_directory + "Data_files\Excel.xlsx"
import %excel_file_path range = "Sheet1 A1:BG100" @freq m 2000M01
Thank you for your time.
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13600
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Relative pathways
How are primary and secondary related? How are they interacting with each other?
Re: Relative pathways
Yes, the primary program mainly calls on the secondary program file to run operations like importing excel files, running models, equations.
For example, you will see lines like in the primary program file:
For example, you will see lines like in the primary program file:
Code: Select all
subroutine inputs
%main_directory = "C:\Documents\Main Directory\"
%BEGQ="1990Q1" 'Start
%ENDQ="2000Q4" 'End
endsub
%secondary_file = %main_directory + "secondary.prg"
call inputs
include %secondary_file
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13600
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Relative pathways
Since you are using an include statement, the secondary program will have access to your %main_directory variable.
Re: Relative pathways
Hi Gareth, thanks for this response and apologies for the late follow up.
But every time I try to run include %secondary.prg, I get an error saying the file doesn't exist because the code seems to read %secondary.prg as string and not its actual definition. Would you know a way around this?
But every time I try to run include %secondary.prg, I get an error saying the file doesn't exist because the code seems to read %secondary.prg as string and not its actual definition. Would you know a way around this?
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13600
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Relative pathways
Ah, sorry, yes, forgot. You can’t use string variables with an include.
Return to “General Information and Tips and Tricks”
Who is online
Users browsing this forum: No registered users and 2 guests
