Page 1 of 1

Check if control variable is defined

Posted: Fri Feb 28, 2025 3:04 am
by paues
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}

Re: Check if control variable is defined

Posted: Tue Mar 11, 2025 1:30 am
by paues
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}

Re: Check if control variable is defined

Posted: Tue Mar 11, 2025 3:01 am
by paues
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

Re: Check if control variable is defined

Posted: Tue Mar 11, 2025 2:46 pm
by EViews Matt
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

Re: Check if control variable is defined

Posted: Tue Mar 11, 2025 3:01 pm
by paues
Thanks, Matt! I appreciate your simplifications :)