How can I test if an object exists?

For questions regarding programming in the EViews programming language.

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

Thommo
Posts: 14
Joined: Wed Sep 17, 2008 10:56 am

How can I test if an object exists?

Postby Thommo » Wed Sep 17, 2008 2:00 pm

How can I test if an object exists in my workfile?

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

Postby EViews Gareth » Wed Sep 17, 2008 2:16 pm

You can use the @isobject command to do this:

Code: Select all

if @isobject("my_ser") then
   delete my_ser
endif

Victoria
Posts: 5
Joined: Wed Feb 17, 2010 3:47 am

Use of @isobject function

Postby Victoria » Wed Feb 17, 2010 4:08 am

Hi,
I have tried using the @isobject in my program to make it skip non-existing series, however I am having trouble making it work. When running the statement on a series that doesn't exist:

Code: Select all

!test = @isobject(NO2_OB_SP_BOR_NA)


Eviews returns the error: ` NO2_OB_SP_BOR_NA is not defined in "!TEST =@ISOBJECT(NO2_OB_SP_BOR_NA)" ´. I thought it should have returned !test=0.

All help is greatly appreciated.

startz
Non-normality and collinearity are NOT problems!
Posts: 3775
Joined: Wed Sep 17, 2008 2:25 pm

Re: How can I test if an object exists?

Postby startz » Wed Feb 17, 2010 7:47 am

Pu the object name in quotes.

Victoria
Posts: 5
Joined: Wed Feb 17, 2010 3:47 am

Re: How can I test if an object exists?

Postby Victoria » Thu Feb 18, 2010 5:16 am

Many thanks for your help and swift reply. Quotes worked for the single statement. I am still having troubles however, with using the command for controlling my loops. I think the problem arises when i try to substitute parts of the string in the loops. The code below searches for the object no1_kk_sp_bof_na which does exist in the workfile, !testing returns one, but !testingtwo and !testingthree returns zero. Is there an other syntax typo causing this or am I trying to do something that can't be done?

rgds
Victoria

Code: Select all

'--This works
   pageselect n
   !testing = @isobject("no1_kk_sp_bof_na")
   pageselect Untitled
   scalar testing = !testing
'--But this does not
   pageselect n
   %bof = "bof"
   !testingtwo = @isobject("no1_kk_sp_{%bof}_na")  ' <-----
   pageselect Untitled
   scalar testingtwo = !testingtwo
'--Nor this
   pageselect n
   %obj = "no1_kk_sp_{%bof}_na"
   !testingthree = @isobject({%obj})   'error returned: NO1_KK_SP_{%BOF}_NA is an illegal or reserved name in "!TESTINGTHREE =@ISOBJECT(NO1_KK_SP_{%BOF}_NA)"
   pageselect Untitled
   scalar testingthree = !testingthree
'--How then to use as control inside loops?

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

Re: How can I test if an object exists?

Postby EViews Gareth » Thu Feb 18, 2010 8:44 am

The line:

Code: Select all

 %bof = "bof"
   !testingtwo = @isobject("no1_kk_sp_{%bof}_na")

Is telling EViews to test for the existence of an object literally called no1_kk_sp{%bof}_na, which doesn't exist. Replacement variables will never work when you put them inside quotes.

Add an extra line:

Code: Select all

 %bof = "bof"
 %temp = "no1_kk_sp_" + %bof + "_na"
   !testingtwo = @isobject(%temp)
Follow us on Twitter @IHSEViews

bobshackleton
Posts: 25
Joined: Wed Mar 23, 2011 6:50 am

Re: How can I test if an object exists?

Postby bobshackleton » Fri Oct 11, 2013 12:47 pm

Hi, I'm having a similar problem but not finding a solution. the following code doesn't create any line graphs, so I think the text inside @isobject is not correct. I have a workfile open and also a database open, and I'm trying to create a line graph only if the series is in the database. Could you explain how to do this correctly?

dbopen {%file_old_cgraw_a} as O_A
pageselect CGRaw_Annual
%all=@wlookup("*","series")
for %i {%all}
%test = "O_A::" + %i
if @isobject(%test) then
line O_A::{%i} {%i}
endif
@uiedit(%stopgo,"OK?")
if %stopgo = "n" then
stop
endif
close @objects
next

bobshackleton
Posts: 25
Joined: Wed Mar 23, 2011 6:50 am

Re: How can I test if an object exists?

Postby bobshackleton » Fri Oct 11, 2013 1:02 pm

I guess I should say that I'm using Eviews 8 Enterprise Edition, 64-bit version.

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

Re: How can I test if an object exists?

Postby EViews Gareth » Fri Oct 11, 2013 2:30 pm

You can't use @isobject on a database link. Use @wquery to query the database for the existence of the series instead.
Follow us on Twitter @IHSEViews

bobshackleton
Posts: 25
Joined: Wed Mar 23, 2011 6:50 am

Re: How can I test if an object exists?

Postby bobshackleton » Fri Oct 11, 2013 3:55 pm

Thanks. I'm having a bit of trouble getting @wquery to work. What am I doing wrong in this code?

%database = %file_old_cgraw_a + ".edb"
%all = @wquery(%database, *, "series")

bobshackleton
Posts: 25
Joined: Wed Mar 23, 2011 6:50 am

Re: How can I test if an object exists?

Postby bobshackleton » Fri Oct 11, 2013 3:57 pm

I guess I should say that I'm getting the following error message:

"%all is not defined or is an illegal command in "%all = @wquery(...)""

The database is correctly named in the error message.

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

Re: How can I test if an object exists?

Postby EViews Gareth » Fri Oct 11, 2013 8:09 pm

You probably want something like:

Code: Select all

%all=@wquery("c:\temp\temp.edb", "type=series", "name")
Follow us on Twitter @IHSEViews

bobshackleton
Posts: 25
Joined: Wed Mar 23, 2011 6:50 am

Re: How can I test if an object exists?

Postby bobshackleton » Tue Oct 15, 2013 10:22 am

Got it - thanks!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 18 guests