cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

"on error" problem under version 15

JohnTesko
1-Visitor

"on error" problem under version 15

I have a program (enclosed) that will define an undefined variable which works fine on version 14 but in version 15 it tells me the variable "rLSL" is undefined and to get it to work, I must define it prior to calling this program which defeats the purpose of the program.

on_error.JPG

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:JohnTesko)

It shows the variable undefined prior to calling the program .

No, there is no way to "undefine" a variable in Mathcad (prior to Prime). You may undefine it for the symbolic processor via rLSL:=rLSL but there is no way to undefine a variable for the numeric processor.

Try to evaluate rLSL immediatly after the supposed undefinition before your routine - I bet it has a value and it will be already 0.

EDIT: Correction, there is a clumsy way to undefine a variable. You may undefine rLSL by assigning it an undefined variable, e.g.: rLSL:=xyz_123

View solution in original post

14 REPLIES 14
Werner_E
25-Diamond I
(To:JohnTesko)

Are you sure that "onerror" catched undefined variables in older versions of Mathcad?

Works fine in version 14.

Werner_E
25-Diamond I
(To:JohnTesko)

John Tesko wrote:

Works fine in version 14.

No, it doesn't!

I just found an older machine with Mathcad 14 M020 on it and tried. Your file throws the same error as MC15.

"onerror" does not catch undefined variables and, as I suspected, never did.

I can't think of a method to catch that error with Mathcad's native commands - it may be possible using scripted components.

This makes no sense.

I'm using version 14.0.0.163 (build 701291152)

I screen shot the results of the program:

It shows the variable undefined prior to calling the program . The program defines the variable. Afterwards it shows the variable is now defined.

Do I have a version the software had a bug which allowed it to work or is there a system option which has to be set for allow it to work?

on_error_2.JPG

Werner_E
25-Diamond I
(To:JohnTesko)

It shows the variable undefined prior to calling the program .

No, there is no way to "undefine" a variable in Mathcad (prior to Prime). You may undefine it for the symbolic processor via rLSL:=rLSL but there is no way to undefine a variable for the numeric processor.

Try to evaluate rLSL immediatly after the supposed undefinition before your routine - I bet it has a value and it will be already 0.

EDIT: Correction, there is a clumsy way to undefine a variable. You may undefine rLSL by assigning it an undefined variable, e.g.: rLSL:=xyz_123

Does this not execute in 15?

Fred Kohlhepp wrote:

Does this not execute in 15?

No. And it doesn't in Mathcad 14 M020 either. It shows the error "This variable is undefined" for the second, fourth and fifth occurence of rLSL.

What do you get in the last line if you change the 0 in the routine to another number? Does is work as expected?

As Richard noted its a bug because it works 🙂

I see what you mean. I modified the replacement of LSL in the program from 0 to 3 and the result is 0 not 3.

Looks like version 15 just has some additional error handling version 14 did not have since 14 did not indicate an error but version 15 highlights the undefined variable.

Thanks

on_error_3.JPG

RichardJ
19-Tanzanite
(To:JohnTesko)

Interesting fluke that it doesn't throw an error in one flavor of 14. In version 13 you get a different error, about a dependency cycle. Maybe when they fixed that they did so in such a way that it doesn't notice that a variable is undefined, which is a bug. The on error statement can not be used to trap an undefined variable. The first thing Mathcad does when evaluating an expression is check for undefined variables (as well as other "top level" errors such as unit problems). If it finds any it throws an error, so the on error statement will never even be executed. You have to resort to much more trickerly (using, as Werner guessed, scripted components) to trap an undefined variable.

I think I will just force the user to have all the variable defined. My attempt which I thought worked was to evaluate the undefined variable without notifiyng the user that a program was handling it.

Using scripts would work fine except too many people are paranoid about viruses and would hit no to evaluating the function.

Thanks.

Werner_E
25-Diamond I
(To:JohnTesko)

I think I will just force the user to have all the variable defined.

Why don't you just set all vital variables to an appropriate default value at the top of the sheet? You may hide those assignments in a collapsed area.

If the user defines a variable, OK, it overrides your default, otherwise its already defined.

You still can insert statements like rLSL:= (without a RHS) as they will do no harm if the user does not fill in a value.

Werner_E
25-Diamond I
(To:JohnTesko)

So you are saying the last screenshot is from MC14? Is there anything in the sheet above the assignment bb:=2?

If not it really looks like the older version of MC14 does the trick which really would be a surprise to me.

I am not sure but I think your MC14 is the very first relase F000 which was really ful of bugs so PTC decided to give away maintainance release M020 for free also to those without maintainance.

In case you are interested - the need to catch undefined variables came up here in the forum some times ago and Richard had provided a scripted component to deal with here http://communities.ptc.com/message/192553#192553

What you see is all there is.

Werner_E
25-Diamond I
(To:Werner_E)

Werner Exinger wrote:

I bet it has a value and it will be already 0.

Lost bet, I guess!

Announcements

Top Tags