@fileexist in if loop

For questions regarding programming in the EViews programming language.

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

jaghetermattis
Posts: 7
Joined: Tue Apr 21, 2015 5:48 am

@fileexist in if loop

Postby jaghetermattis » Tue Apr 21, 2015 6:10 am

Hello,

First time poster. I have an issue with the support command @fileexist in a loop. I need to check if a database exists before I (re)create it, but it seems like my code interprets @fileexist as = 0 and overwrites existing databases at all times. My code:

%blu2011 = "path\blu2011.edb"
%blu2012 = "path\blu2012.edb"
%blu2013 = "path\blu2013.edb"
%blu2014 = "path\blu2014.edb"


for !j = 1 to 4
if @fileexist(%blu201{!j})=0 then
dbcreate blu201{!j}
endif
next

Anyone see the problem here? Would be most grateful for any help.

Best, Matt

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

Re: @fileexist in if loop

Postby EViews Gareth » Tue Apr 21, 2015 7:59 am

Try:

Code: Select all

for !j=1 to 4 %fileref = "%blu201"+@str(!j) if @fileexist({{%fileref}})=0 then ...

jaghetermattis
Posts: 7
Joined: Tue Apr 21, 2015 5:48 am

Re: @fileexist in if loop

Postby jaghetermattis » Wed Apr 22, 2015 2:09 am

Thank you Gareth, much appreciated. However that gives me a "Syntax error in control statement". Does that give you any leads?
I'm using Eviews 8 btw.

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

Re: @fileexist in if loop

Postby EViews Gareth » Wed Apr 22, 2015 7:45 am

Code: Select all

if @fileexist({%fileref})=0 then

jaghetermattis
Posts: 7
Joined: Tue Apr 21, 2015 5:48 am

Re: @fileexist in if loop

Postby jaghetermattis » Thu Apr 23, 2015 2:24 am

Worked like a charm - thank you so much Gareth.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests