evaluating if an attribute exists using @isobject

For questions regarding programming in the EViews programming language.

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

BT454
Posts: 135
Joined: Wed Aug 02, 2017 6:07 am

evaluating if an attribute exists using @isobject

Postby BT454 » Fri Apr 26, 2019 11:15 am

Hi!
I'm wondering if it's possible to check if a specific attribute exists for a group of data series using the @isobject function.
Thinking something like the code below, but my job is crashing saying that "some_attribute" is not defined. I'm sure my syntax is off.
Any help is appreciated!
Thanks,
Bob

string series_list = ""
for %x {%string_of_series}
!x = @isobject({%x}.attr(some_attribute))
if !x = = 0 then
string series_list = {series_list} + %x + " "
else
endif
next

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

Re: evaluating if an attribute exists using @isobject

Postby EViews Gareth » Fri Apr 26, 2019 11:22 am

Code: Select all

string series_list = ""
for %x {%string_of_series}
%xx = {%x}.attr(some_attribute)
if @len(%xx)=0 then
string series_list = {series_list} + %x + " "
else
endif
next
Follow us on Twitter @IHSEViews

BT454
Posts: 135
Joined: Wed Aug 02, 2017 6:07 am

Re: evaluating if an attribute exists using @isobject

Postby BT454 » Fri Apr 26, 2019 11:46 am

Thanks!
I'm receiving an error message saying the named attribute (in this case UNIT) is not defined.
Here is the exact code, and I've attached the workfile. I'm wondering if it's a case sensitive issue (i.e. I have the attribute defined as "Unit" in the code and the workfile, but it appears the program is looking for "UNIT")?
Thanks again for the help!

group g *
%vars = g.@members
string series_list = ""
for %x {%vars}
%xx = {%x}.attr(Unit)
if @len(%xx)=0 then
string series_list = {series_list} + %x + " "
else
endif
next
Attachments
testCDB042019_regionals.wf1
(936.18 KiB) Downloaded 217 times

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

Re: evaluating if an attribute exists using @isobject

Postby EViews Gareth » Fri Apr 26, 2019 11:55 am

Code: Select all

group g *
%vars = g.@members
string series_list = ""
for %x {%vars}
   %xx = {%x}.@attr("Unit")
   if @len(%xx)=0 then
      series_list = series_list + %x + " "
   else
   endif
next
Follow us on Twitter @IHSEViews


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 26 guests