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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Working with undefined variables

MJG
18-Opal
18-Opal

Working with undefined variables

Is there anything within Mathcad similar to an IsUndefined function? I'm trying to include some built-in checks for a template I'm working on.

Section "A" of the template has a check "A" (true or false). If check "A" fails, the user needs to continue on to section "B" of the template where exists a check "B". At the end of the document, I want to include something such as CheckAB := CheckA OR CheckB. Since a variable is undefined in section "B" of the document, CheckB has an undefined error, so my final CheckAB function returns an undefined error. I'd like for it to ignore the undefined variable in CheckB and just return the value of CheckA.

Something like this:

CheckAB: if(IsUndefined(CheckB),CheckA,CheckA OR CheckB)

Similarly, it could be written as:

CheckAB := CheckA OR if(IsUndefined(CheckB),False,CheckB)

IsUndefined(x) would return true if x is undefined, and false if x is defined.

Edit: I should clarify that this template will be used by persons running v13-v15.

ACCEPTED SOLUTION

Accepted Solutions
RichardJ
19-Tanzanite
(To:MJG)

Well, I'm glad it was useful to you

View solution in original post

4 REPLIES 4
Fred_Kohlhepp
23-Emerald I
(To:MJG)

Sounds like what you're looking for is "on error"

B := NaN on error 5/x

will return B. B will either be 5/x or NaN if there is any error evaluating 5/x.

This can be built to whatever level of complexity you can imagine.

Thanks for the input. Unless I'm missing something, though, I don't think "on error" traps the undefined error. To use your example, if x is undefined, B will not return NaN, it will show an undefined error.

MJG
18-Opal
18-Opal
(To:MJG)

What a coincidence - it appears the second most recent Mathcad post is in regard to this very same issue. I originally did a search in the forum for an answer, but didn't see anything that related to my question. I just checked the Mathcad forum homepage and saw this post:

http://communities.ptc.com/message/192609#192609

Thanks to Richard Jackson for his answer on that post. I made a slight modification to your IsDefined custom function to make it similar to the nz function in Microsoft Access. If you see this post, please reply and I'll credit you with the answer.

RichardJ
19-Tanzanite
(To:MJG)

Well, I'm glad it was useful to you

Announcements

Top Tags