Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
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
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!
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.
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