How to skip to next if there is an error?

For questions regarding programming in the EViews programming language.

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

cmgconsulting
Posts: 38
Joined: Mon Nov 17, 2008 8:25 am

How to skip to next if there is an error?

Postby cmgconsulting » Tue Dec 16, 2008 8:53 am

I'm trying to write a program that will take all of the equation objects and put them into a spool and then name them based on a series called "eqname"

The problem is that I do not ALWAYS have an object called whatever is in eqname(39*!i). How can I tell it to just skip any problems and continue the program? If I tell it to accept say 1000 errors, then it won't name the objects anymore. Not sure why? Any help?

Code: Select all

spool myspool
for !i=1 to 320
%cxname = eqname(39*!i)
%eqname = %cxname

myspool.append  {%eqname}

if !i<10 then
myspool.name untitled0{!i} {%eqname}
else
myspool.name untitled{!i} {%eqname}
endif

next

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

Re: How to skip to next if there is an error?

Postby startz » Tue Dec 16, 2008 9:04 am

cmgconsulting wrote:I'm trying to write a program that will take all of the equation objects and put them into a spool and then name them based on a series called "eqname"

The problem is that I do not ALWAYS have an object called whatever is in eqname(39*!i). How can I tell it to just skip any problems and continue the program? If I tell it to accept say 1000 errors, then it won't name the objects anymore. Not sure why? Any help?

Code: Select all

spool myspool
for !i=1 to 320
%cxname = eqname(39*!i)
%eqname = %cxname

myspool.append  {%eqname}

if !i<10 then
myspool.name untitled0{!i} {%eqname}
else
myspool.name untitled{!i} {%eqname}
endif

next

This isn't a direct answer to your question, but the @isobject() function might help you avoid the errors.

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

Re: How to skip to next if there is an error?

Postby EViews Gareth » Tue Dec 16, 2008 9:10 am

As Startz already pointed out, you can use the @isobject function to check whether an object exists before doing something to that object, which should avoid any errors. However you can also crudely program around errors by using the @errorcount function to tell you how many errors have occurred in the program so far. This lets you check whether a line of program has caused an error or not (by seeing if @errorcount is higher after that line).
Follow us on Twitter @IHSEViews


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 29 guests