Page 1 of 1

@fileexist in if loop

Posted: Tue Apr 21, 2015 6:10 am
by jaghetermattis
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

Re: @fileexist in if loop

Posted: Tue Apr 21, 2015 7:59 am
by EViews Gareth
Try:

Code: Select all

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

Re: @fileexist in if loop

Posted: Wed Apr 22, 2015 2:09 am
by jaghetermattis
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.

Re: @fileexist in if loop

Posted: Wed Apr 22, 2015 7:45 am
by EViews Gareth

Code: Select all

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

Re: @fileexist in if loop

Posted: Thu Apr 23, 2015 2:24 am
by jaghetermattis
Worked like a charm - thank you so much Gareth.