Check if control variable is defined

For questions regarding programming in the EViews programming language.

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

paues
Posts: 212
Joined: Fri Apr 15, 2011 7:16 am
Location: Stockholm, Sweden

Check if control variable is defined

Postby paues » Fri Feb 28, 2025 3:04 am

Is there some way to check if a control variable is previously defined? I've tried the following convoluted way, but the error ('!POSSIBLY_DEFINED_VARIABLE is not defined in "IF !POSSIBLY_DEFINED_VARIABLE THEN" on line 6.') is apparently not impressed by my magic.

Code: Select all

!old_maxerrcount = @maxerrcount if @maxerrcount = @errorcount then setmaxerrs {!old_maxerrcount} + 1 endif !old_errorcount = @errorcount if !possibly_defined_variable then endif if @errorcount > !old_errorcount then @uiprompt("UNDEFINED") else    @uiprompt("defined") endif seterrcount {!old_errorcount} setmaxerrs {!old_maxerrcount}
Last edited by paues on Tue Mar 11, 2025 1:30 am, edited 1 time in total.

paues
Posts: 212
Joined: Fri Apr 15, 2011 7:16 am
Location: Stockholm, Sweden

Re: Check if control variable is defined

Postby paues » Tue Mar 11, 2025 1:30 am

Two things:

1. I think that the documentation of @maxerrcount is somewhat confusing. Perhaps this confusion stems from me not being a native English speaker, but the way I read the documentation ("the maximum number of errors that a program may encounter before execution is halted"), I thought that if @maxerrcount for instance was set to 1, then execution would not stop when encountering the first error but rather at the second error.

2. Beyond me misinterpreting the documentation, I had made another coding error (writing setmaxerr instead of setmaxerrs). I have corrected it in the original question.

A functioning version of my somewhat convoluted code to check if a control variable is undefined is:

Code: Select all

!old_maxerrcount = @maxerrcount if @maxerrcount <= @errorcount + 1 then setmaxerrs {!old_maxerrcount} + 1 endif !old_errorcount = @errorcount if !possibly_defined_variable then endif if @errorcount > !old_errorcount then @uiprompt("UNDEFINED") else @uiprompt("defined") endif seterrcount {!old_errorcount}

paues
Posts: 212
Joined: Fri Apr 15, 2011 7:16 am
Location: Stockholm, Sweden

Re: Check if control variable is defined

Postby paues » Tue Mar 11, 2025 3:01 am

Regarding 1, ChatGPT seems to think that the documentation is clear. I have elaborated on my confusion in this chat https://chatgpt.com/share/67d009b0-ec34 ... c3e88aac62

EViews Matt
EViews Developer
Posts: 583
Joined: Thu Apr 25, 2013 7:48 pm

Re: Check if control variable is defined

Postby EViews Matt » Tue Mar 11, 2025 2:46 pm

Hello,

The setmaxerrs command specifies which error will halt the program, e.g. setmaxerrs 4 stopping at the 4th error, not the number of allowed errors, e.g. setmaxerrs 4 stopping at the 5th error. A difference of only one error, but I understand how the description of setmaxerrs could be ambiguous. Recognizing that the setting needs be only one more than you initially thought, your example code only requires a minor change. I've added a few other cleanup and simplification changes.

Code: Select all

!old_maxerrcount = @maxerrcount !old_errorcount = @errorcount setmaxerrs !old_errorcount+2 ' +2 instead of +1 if !possibly_defined_variable then endif if @errorcount > !old_errorcount then @uiprompt("UNDEFINED") else @uiprompt("defined") endif seterrcount !old_errorcount setmaxerrs !old_maxerrcount

paues
Posts: 212
Joined: Fri Apr 15, 2011 7:16 am
Location: Stockholm, Sweden

Re: Check if control variable is defined

Postby paues » Tue Mar 11, 2025 3:01 pm

Thanks, Matt! I appreciate your simplifications :)


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests