How can I test if an object exists?
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
How can I test if an object exists?
How can I test if an object exists in my workfile?
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13583
- Joined: Tue Sep 16, 2008 5:38 pm
You can use the @isobject command to do this:
Code: Select all
if @isobject("my_ser") then
delete my_ser
endif
Use of @isobject function
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:
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.
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)All help is greatly appreciated.
-
startz
- Non-normality and collinearity are NOT problems!
- Posts: 3796
- Joined: Wed Sep 17, 2008 2:25 pm
Re: How can I test if an object exists?
Pu the object name in quotes.
Re: How can I test if an object exists?
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
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: 13583
- Joined: Tue Sep 16, 2008 5:38 pm
Re: How can I test if an object exists?
The line:
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"
!testingtwo = @isobject("no1_kk_sp_{%bof}_na")
Add an extra line:
Code: Select all
%bof = "bof"
%temp = "no1_kk_sp_" + %bof + "_na"
!testingtwo = @isobject(%temp)
-
bobshackleton
- Posts: 25
- Joined: Wed Mar 23, 2011 6:50 am
Re: How can I test if an object exists?
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
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?
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: 13583
- Joined: Tue Sep 16, 2008 5:38 pm
Re: How can I test if an object exists?
You can't use @isobject on a database link. Use @wquery to query the database for the existence of the series instead.
-
bobshackleton
- Posts: 25
- Joined: Wed Mar 23, 2011 6:50 am
Re: How can I test if an object exists?
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")
%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?
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.
"%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: 13583
- Joined: Tue Sep 16, 2008 5:38 pm
Re: How can I test if an object exists?
You probably want something like:
Code: Select all
%all=@wquery("c:\temp\temp.edb", "type=series", "name")
-
bobshackleton
- Posts: 25
- Joined: Wed Mar 23, 2011 6:50 am
Re: How can I test if an object exists?
Got it - thanks!
Who is online
Users browsing this forum: No registered users and 2 guests
