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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

If Exist or If Not Exist

tietjee
15-Moonstone

If Exist or If Not Exist

I am writing a program and would like to use an if statement  with the following format

 

if X exist

if X does not exist

 

Running Prime 5. I did not see this as an option in the help files.

Mathcad 15 does not appear to have the feature either

 

David

5 REPLIES 5
tietjee
15-Moonstone
(To:tietjee)

Solved my own question.  It is not as clean as other programming languages.  Attached is my solution, which will work for my application.

Mathcad has a (non-programming, so it works even in Express) if statement like the one in EXCEL:

 

if(boolean test, result if true, result if false)

Try please the try operator!

Werner_E
25-Diamond I
(To:tietjee)

As you already noticed there is unfortunately no way to check if a variable is already defined.
You would have to write a program which saves the worksheet and scans the xml-file in the saved archive (a mcdx-file is just a renamed zip archive) for the existence of a variable definition.

Also Valerys suggestion does not help as Prime would reject the call to the function if you provide an undefined variable as argument and the function so would be never called.

But if just checking if a (defined) variable has the "value" NaN is enough, your solution can be simplified a little bit by omitting the local variable y. Furthermore you could follow Freds advice to use the if-function instead of the programming if-statement. This has the benefit that the routine will also work in the limited Prime Express. The definition will be shorter that way, but also a little bit less clear.

B.png

tietjee
15-Moonstone
(To:Werner_E)

Thank you everybody for the support.  I have made the change to the code snippet,

 

The decision is made in a program which is represented by "Variable Not..."and "Variable..."  Each one will replaced by several lines of code.

Again,  Thank you

Announcements

Top Tags